How to Include CSS Within HTML Web Pages
Use the style attribute if you're only applying the CSS to one page., Create a separate file for CSS alone then link it to the HTML, if you plan on applying CSS to multiple pages., Add properties and values to change something specific in your...
Step-by-Step Guide
-
Step 1: Use the style attribute if you're only applying the CSS to one page.
The easiest way to incorporate CSS into the coding is by using the 'style' attribute.
You can write this between the 'head' tags; OR by inserting the attribute between the HTML codes themselves.
This is called 'embedding' or 'internal styles'. -
Step 2: Create a separate file for CSS alone then link it to the HTML
This process is called 'external linking' or 'internal styles'.
This is another method for applying CSS attributes.
This will make it easier for you to edit and manage your files.
By separating your files from HTML, this will reduce the amount of work you need to do in the future.
But if you just want to edit a few pages, then simply insert the codes within the tags themselves as previously mentioned. , 'Properties' are words that refer to a web element (such as color or font size) being altered. 'Values' are exact descriptions of how the properties should be (such as numerical values for font size, and color names).
Properties are enclosed in curly brackets, whereas values are followed by a colon. , There are several values for CSS, but there are general units you will want to use for basic purposes.
These are: px (for pixels); em (for font size); and % (for specifying width and height percentages).
Use '0' if you don't want to state a value for an element. , You can use names (orange, black, navy, green, etc.), RGB values (ranging from 0 to 255), or hex codes (#ff0000).
Using hex codes actually gives you more control over the exact shade you want.
That's because the last number in the six-digit hex code is responsible for the precise color. , There are generally three types of font families:
Verdana, Times New Roman, and Arial.
These are the safest fonts to use because most computers and browsers have them.
However, the great thing about CSS is that you can add up to three different fonts.
So if the first choice is not available on a user's computer, it will automatically go to the next one in line.
Separate your choices using commas. , For CSS beginners, you can add margins, borders, and padding for a clean look.
A 'margin' is used outside of an element (such as images or text); while 'padding' is the space inside the element.
As stated above, you can use px units to specify for border, margin, and padding properties.
You can even make them dashed, filled with color, solid, grooved, or dotted. , If you saved a separate file for CSS, link it by using the <link rel='stylesheet' href='style.css' type='text/css' /> command. -
Step 3: if you plan on applying CSS to multiple pages.
-
Step 4: Add properties and values to change something specific in your file.
-
Step 5: Learn and use the basic units.
-
Step 6: Don't forget to make your CSS pop with color!
-
Step 7: Remember to make your web page stand out with CSS font styles and sizes.
-
Step 8: Experiment with some basic adjustments.
-
Step 9: Put them all together by saving the files.
Detailed Guide
The easiest way to incorporate CSS into the coding is by using the 'style' attribute.
You can write this between the 'head' tags; OR by inserting the attribute between the HTML codes themselves.
This is called 'embedding' or 'internal styles'.
This process is called 'external linking' or 'internal styles'.
This is another method for applying CSS attributes.
This will make it easier for you to edit and manage your files.
By separating your files from HTML, this will reduce the amount of work you need to do in the future.
But if you just want to edit a few pages, then simply insert the codes within the tags themselves as previously mentioned. , 'Properties' are words that refer to a web element (such as color or font size) being altered. 'Values' are exact descriptions of how the properties should be (such as numerical values for font size, and color names).
Properties are enclosed in curly brackets, whereas values are followed by a colon. , There are several values for CSS, but there are general units you will want to use for basic purposes.
These are: px (for pixels); em (for font size); and % (for specifying width and height percentages).
Use '0' if you don't want to state a value for an element. , You can use names (orange, black, navy, green, etc.), RGB values (ranging from 0 to 255), or hex codes (#ff0000).
Using hex codes actually gives you more control over the exact shade you want.
That's because the last number in the six-digit hex code is responsible for the precise color. , There are generally three types of font families:
Verdana, Times New Roman, and Arial.
These are the safest fonts to use because most computers and browsers have them.
However, the great thing about CSS is that you can add up to three different fonts.
So if the first choice is not available on a user's computer, it will automatically go to the next one in line.
Separate your choices using commas. , For CSS beginners, you can add margins, borders, and padding for a clean look.
A 'margin' is used outside of an element (such as images or text); while 'padding' is the space inside the element.
As stated above, you can use px units to specify for border, margin, and padding properties.
You can even make them dashed, filled with color, solid, grooved, or dotted. , If you saved a separate file for CSS, link it by using the <link rel='stylesheet' href='style.css' type='text/css' /> command.
About the Author
Alexis Price
Specializes in breaking down complex home improvement topics into simple steps.
Rate This Guide
How helpful was this guide? Click to rate: