HTML Tutorials

Overview

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>

Place 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>

HTML Notes:

  • In our HTML section the term “tag” and “element” are often used interchangeably to refer to both the tag used to create a page element and the element created by the tag (<p> tag = <p> element = paragraph on the page)
  • HTML5 is not case sensitive; so <P> is the same as <p>, <H1> is the same as <h1>
  • Global attributes can be used with all HTML tags and are therefore not mentioned on every tag page
  • To write clean, readable HTML code, it is best to use indentation whereas elements within elements are indented (tabbed or spaces) to create something that looks like a project outline
  • The browser will automatically remove any extra spaces and lines in your HTML code when the page is displayed
  • Double quotes or single quotes can be used around HTML attribute values, but when the attribute value itself contains one form of quote, it will be necessary to use the other around the attribute

We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.