With CSS you can control the colors, background images, font choice, text size, spacing, positioning, overall page layout for all screen sizes, and more.

CSS can be added to an HTML document in 3 ways:

Note
See the CSS Tutorial on Placing Styles in Your Document for a much more detailed explanation of everything below, including the rules of specificity, which are extremely important when deciding where and how to place your CSS styles. The following is just a brief overview of the three ways to add CSS to your document.

Inline CSS

This is the least desirable way to include CSS styling in your document, because there can be many pages to a site, and hundreds, if not thousands of HTML elements, finding and updating the inline styles can be a nightmare.

				
					<p style="color: red;">A paragraph with red text.</p>
				
			

Multiple style rules can be included in on element as long as each rule is ended with a semi-colon.

				
					<p style="color: red; font-size: 16px;">A paragraph with red text.</p>
				
			

Placing Styles in the Head of the Document

While more desirable than placing style inline, this is still not the best way to style a page. A typical site may have hundreds of pages and going through each to update an element’s style will prove tedious at best.

				
					<head>
<title>HTML Template</title>
<!-- styles -->
<style>
    #primary {
        color: red;
        font-size: 18px;
    }
    #secondary {
        margin-top: 35px;
    }
</style>
</head>
				
			

Linking to External Style Sheets

This is the much preferred method for stying the elements on the page, as all the rules can be found in only a few locations and will be easier to update.

				
					<head>
<meta charset="UTF-8">
<meta name="description" content="Free Web Tutorials">
<meta name="keywords" content="HTML, CSS, JavaScript, PHP, SQL">
<meta name="author" content="1SMARTchicken">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML Template</title>
<!-- styles -->
<link rel="stylesheet" type="text/css" href="/docs/style.css">
<link rel="stylesheet" type="text/css" href="/docs/sidebar-styles.css">
</head>