HTML Tag Reference
This is a list of the tags we have used in class. For a full list, see w3schools.com/tags.
These are the fundamental container elements used to organize and style your webpage content.
| Tag | Description |
|---|---|
<div> </div> | Generic block element container (used for large sections of content) |
<span> </span> | Generic inline element container – good for styling a short piece of text) |
References: Headings, Paragraphs
| Tag | Description |
|---|---|
<h1> </h1> | Level 1 heading – larger and bolder (should be used once per page) |
<h2> </h2> | Level 2 heading – large and bold |
<p> </p> | A paragraph of text |
<br> | Line break |
<hr> | Horizontal rule – a horizontal line across the page |
Reference: w3schools.com/html/html_formatting.asp
| Tag | Effect | Description |
|---|---|---|
<b> / <strong> | Bold / Strong Emphasis | Makes text bold (<strong> implies greater importance). |
<i> / <em> | Italic / Emphasized | Makes text italic (<em> implies stress or emphasis). |
<mark> | Highlighted | Highlights a section of text. |
<small> | Smaller text | Renders text one size smaller. |
<del> / <ins> | Shows text that has been deleted or inserted from a document. | |
<sub> / <sup> | H2O / E=mc2 | Subscript (below the line) and Superscript (above the line). |
Live Demo:
This is a bold word and this is an important phrase.
The final answer is 50 42.
Water's formula is H2O and squared means x2.
Please highlight this key information to study later.
Reference: w3schools.com/html/html_links.asp
| Tag | Description |
|---|---|
<a href="page.html">Display Text</a> | Basic link |
<a name="anchor-name"> | An anchor point inside a document |
<a href="#anchor-name">Display Text</a> | A link to an anchor point inside the same webpage |
Reference: w3schools.com/html/html_images.asp
| Tag | Description |
|---|---|
<img src="myimage.png"> | Show an image that is stored in the same folder as the webpage |
<img src="http://www.website.com/image.jpg"> | Show an image that is stored on another website |
<img src="myimage.png" width="100px" height="100px"> | Show an image with a specified width and/or height. Units can be px or % (100% would be the entire width of the container). |
Reference: w3schools.com/html/html_lists.asp
Unordered List Example: <ul>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
- Coffee
- Tea
- Milk
Unordered list. Each list item will get a bullet.
Ordered List Example: <ol>
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
- Coffee
- Tea
- Milk
Ordered list. Each list item will be numbered.
A list must begin with a <ul> or <ol> tag.
Only <li> tags should be inside <ul> or <ol> tags.
<li> tags should only be used inside <ul> or <ol> tags.
Reference: w3schools.com/html/html_tables.asp
Tables are used to display data in rows and columns. Use `<thead>` for headers and `<tbody>` for the main data.
| Tag | Description |
|---|---|
<table></table> | The wrapper for the entire table. |
<thead></thead> | The container for the table header row(s). |
<tbody></tbody> | The container for the main table body row(s). |
<tr></tr> | A table row. |
<th></th> | A table header cell (usually bold and centered). |
<td></td> | A table data cell. |
Code Example:
<table>
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Grade</th>
</tr>
</thead>
<tbody>
<tr>
<td>Jane</td>
<td>Doe</td>
<td>A</td>
</tr>
<tr>
<td>John</td>
<td>Smith</td>
<td>B+</td>
</tr>
</tbody>
</table>
Live Demo:
| First Name | Last Name | Grade |
|---|---|---|
| Jane | Doe | A |
| John | Smith | B+ |
CSS Reference
- Create a file named something like
styles.css. - In the
<head>section of each webpage you want to style with this file, add the link tag:<link rel="stylesheet" href="styles.css>
/* Example head section with title and CSS link. There might be other tags in the head section also */
<head>
<title>My Webpage Title</title>
<link rel="stylesheet" href="styles.css">
</head>
| CSS Syntax | Description | Example |
|---|---|---|
tag { } | Style all the elements that use that tag (e.g., all <a> elements) | a { color: white; } |
#name { } | Style the element with the unique id="name" attribute | #main-heading { color: blue; } |
.class-name { } | Style every element with the class="class-name" attribute | .button { background-color: darkgray; } |
.class tag { } |
Descendant selector. Styles any <tag> that is inside an element with class="class". |
.container p { color: red; } |
These are general properties used for styling text and layout, outside of the core Box Model dimensions.
| Property | Description | Examples |
|---|---|---|
color: | Sets the text color (named color, rgb value, or hex value) | color: red;, fcolor: rgb(128, 128, 255);, color: #12A3B7; |
background-color: | Sets the background color | background-color: white; |
font-family: | Set a font. Must be a name the browser will recognize | font-family: Courier |
font-size: | Sets the size of the font. Usually measured in px or pt | font-size: 36px; |
text-align: | Determines how text is aligned inside an element | text-align: center; |
box-shadow: | Creates a shadow below the element | box-shadow: 0px 8px 20px darkgray; |
display: | Adjusts how the HTML elements inside the container are positioned (e.g., block, inline, flex) | display: flex; |
text-decoration: | Sets the underline, strike-through, etc. of the text (e.g., underline, none) | text-decoration: none; |
The Box Model is the most important concept in CSS. Every HTML element is treated as a rectangular box, and this model explains how space is added around its content. Understanding this is key to sizing and positioning elements.
(Space inside the Padding)
Padding (Space inside Border)
The Content is the actual text or image.
The Padding is the space inside the element, between the content and the border.
The Border is the line that surrounds the padding and content.
The Margin is the clear space outside the element, separating it from other elements.
Box Model Properties
| Property | Description | Examples |
|---|---|---|
width: and height: | Sets the size of the content box. Units can be px, %, vw, vh | width: 100%;, height: 50vh; |
max-width: and max-height: | Sets the maximum width or height for elements. Prevents growth beyond this size. | max-width: 200px; |
min-width: and min-height: | Sets the minimum width or height for elements. Prevents shrinking below this size. | min-width: 100px; |
padding: | Sets the padding or space around the content inside the background. | padding: 10px |
border: | Sets the border size, style, and color. | border: 4px solid blue; |
border-radius: | Rounds the corners of the border. | border-radius: 10px; |
margin: | Set the space around the element, outside of the background. | margin: 20px |
CSS properties rely on units of measurement to define size, distance, and spacing. These units are split into two main types: absolute units (fixed size) and relative units (based on another element or the viewport).
| Unit | Description | Example |
|---|---|---|
px (Pixels) | An absolute unit. One pixel is one physical dot on the screen. Not ideal for responsiveness as it doesn't scale. | width: 200px; |
% (Percentage) | A relative unit based on the size of the parent element. Often used for fluid widths. | width: 50%; (50% of the parent's width) |
em | A relative unit based on the font-size of the element's parent. Scales well if the parent's font changes. | padding: 1.5em; (1.5 times the parent's font size) |
vh (Viewport Height) | A relative unit equal to 1% of the viewport (browser window) height. Great for elements that need to fill the screen vertically. | height: 100vh; (Full screen height) |
vw (Viewport Width) | A relative unit equal to 1% of the viewport (browser window) width. Useful for making elements or text size scale with the screen width. | font-size: 5vw; (5% of the screen width) |
The position property specifies the type of positioning method used for an element. This is key for creating complex layouts and overlapping elements.
| Value | Description |
|---|---|
static | Default value. The element is not positioned in any special way; it is always positioned according to the normal flow of the page. |
relative | The element is positioned relative to its normal position. Setting top, right, bottom, or left will move it from its static position without affecting other elements. |
absolute | The element is positioned relative to its nearest positioned ancestor (an ancestor with a position other than static). If no positioned ancestor exists, it uses the <body>. |
fixed | The element is positioned relative to the browser window (viewport). It will stay in the same place even when the page is scrolled. |
sticky | A hybrid of relative and fixed. The element acts like relative until it hits a specified offset (e.g., top: 0) during scroll, at which point it "sticks" in place like fixed. |
Live Demo:
Scroll inside the demo container to see sticky in action. The fixed box is positioned relative to the whole browser window.
Scrollable content to push the static and relative boxes down...
(Default position setting)
(top: 10px, left: 30px)
(top: 40px, right: 10px)
More scrollable content...
Example Code:
/* The parent container *must* be positioned for 'absolute' to work predictably */
.container {
position: relative;
}
.box-relative {
position: relative;
top: 10px;
}
.box-absolute {
position: absolute;
top: 0;
right: 0;
}
.box-fixed {
position: fixed;
bottom: 10px;
}
.box-sticky {
position: sticky;
top: 0;
}
Used when display: flex; is set on a container. For a good flex property reference: CSS-Tricks Flexbox Guide.
| Property | Description | Examples |
|---|---|---|
display: flex; | Sets the element to display its contents using flex properties | - |
flex-direction: | Determines whether elements should be arranged horizontally or vertically | flex-direction: row;, flex-direction: column; |
justify-content: | Determines how elements are aligned along the main axis (horizontal/vertical) | justify-content: center;, justify-content: space-between; |
align-items: | Determines how elements are aligned along the cross axis (perpendicular to main axis) | align-items: center;, align-items: stretch; |
flex-wrap: | Determines if the container will wrap to a new line when it runs out of room. | flex-wrap: wrap;, flex-wrap: nowrap; |
Live Demo:
Use the dropdowns to see how the flex properties change the layout of the blue boxes inside the dashed container.
Example Code:
/* The Parent Container */
.container {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
flex-wrap: wrap;
height: 300px;
}
/* The Child Items */
.item {
width: 100px;
height: 100px;
margin: 10px;
}
These properties allow you to set images or color gradients as the background of any element and control how they are displayed and scaled.
| Property | Description | Examples |
|---|---|---|
background-image: | Specifies the path to an image file, often a URL or gradient. | background-image: url("image.jpg");, background-image: linear-gradient(...); |
linear-gradient() | Creates a smooth transition between two or more colors. Used with background-image. | background-image: linear-gradient(to right, red, blue); |
background-position: | Sets the starting position of a background image (defaults to top-left). | background-position: center;, background-position: 50% 50%; |
background-size: | Defines how the background image should be scaled relative to the container. | background-size: cover;, background-size: contain;, background-size: 100% 100%; |
background-repeat: | Determines if and how a background image is repeated. | background-repeat: no-repeat; |
Demo:
Filters let you apply visual effects to elements, like blur, saturation, or color shift. They are often used for image effects or interactive elements.
| Function | Description | Example |
|---|---|---|
blur() | Blurs the element by a specified radius. | filter: blur(5px); |
grayscale() | Converts the color to shades of gray (0% to 100%). | filter: grayscale(100%); |
saturate() | Adjusts color saturation (100% is normal, 200% is double). | filter: saturate(150%); |
drop-shadow() | Applies a shadow to the element (similar to box-shadow but applied to the content shape). | filter: drop-shadow(0 0 10px black); |
Demo: Hover over the image to apply a grayscale and blur filter, and a subtle drop-shadow effect.
Transitions create a smooth, timed animation when a CSS property value changes (e.g., on hover or active states).
| Property | Description | Example |
|---|---|---|
transition: | Shortcut for all transition properties. The duration is the only required value. | transition: 1s; or transition: all 0.5s ease; |
transition-property | The CSS property name(s) to animate. Use all for everything. | transition-property: background-color, transform; |
transition-duration | How long the transition should take (in seconds or milliseconds). | transition-duration: 0.5s; or 500ms; |
transition-timing-function | The speed curve of the transition (e.g., ease, linear, ease-in-out). | transition-timing-function: ease-in-out; |
transition-delay | How long to wait before the transition starts. | transition-delay: 0.2s; |
Demo: Hover over the box to see its background color and size smoothly transition over 0.5 seconds.
Animations allow complex, multi-step motion without user interaction, defined using @keyframes.
| Property | Description | Example |
|---|---|---|
animation: | Shortcut for all animation properties. The name and duration are required values. | animation: bounce 1.5s; or animation: bounce 1.5s infinite; |
@keyframes | Defines the steps of the animation (e.g., 0%/from to 100%/to). | @keyframes my-bounce { ... } |
animation-name | The name of the @keyframes rule to use. | animation-name: bounce; |
animation-duration | How long one cycle of the animation takes. | animation-duration: 1.5s; |
animation-iteration-count | How many times the animation should run (e.g., a number or infinite). | animation-iteration-count: infinite; |
Demo: This box is continuously running a simple bounce animation.
Centering elements
To center a block element (e.g., a <div>) that has a defined width, you use margins, as explained in the Box Model section. For inline elements (like <a> or <img>), you need to set display: block; first.
selector {
display: block;
width: fit-content;
margin-left: auto;
margin-right: auto;
}
Select Child Elements (Descendant Selector)
Use a space between two selectors to target an element (the child) that is nested anywhere inside another element (the parent). This is useful for styling elements in a specific area of your page without using a class name on the child.
/* Styles any <h1> that is inside an element with class "my-class" */
.my-class h1 {
color: red;
border-bottom: 2px solid red;
}
Remove default margin
Elements like <h1> and <p> have default top/bottom margin. Set margin: 0px; to remove it.
h1 {
margin: 0px;
}
Give multiple selectors the same style
Separate selectors with a comma to apply the same styles to all of them.
h1, #title, p {
background-color: red;
}
Change look when element is hovered
Use the selector:hover pseudo-class to apply different styles when the element is hovered over with a mouse pointer.
a:hover {
color: red;
text-decoration: underline;
}