Skip to main content
April 1, 2026Dan Rodney/6 min read

Intro to Cascading Style Sheets (CSS)

Master the fundamentals of styling web content

Core CSS Concepts

Style Tag

Contains CSS rules within the HTML head section. Acts as the container for all internal stylesheet definitions.

Tag Selectors

Target all instances of specific HTML elements. Provide default appearance settings for consistent styling.

CSS Properties

Define visual characteristics like font-family, font-size, color, and line-height for enhanced typography control.

Topics Covered in This HTML & CSS Tutorial:

The Style Tag, Tag Selectors, the Font-size, Font-family, Color, & Line-height Properties, Hexadecimal Color Codes

Exercise Preview

intro to css

CSS Implementation Process

1

Add Style Tags

Insert style tags in the HTML head section to create a container for CSS rules

2

Define Selectors

Create tag selectors to target specific HTML elements like h1, h2, and p tags

3

Apply Properties

Set font-family, font-size, color, and line-height values for each selector

4

Test and Refine

Save the file and reload in browser to see styling changes applied

Exercise Overview

In this exercise, you'll transform plain HTML content into a visually engaging webpage using Cascading Style Sheets (CSS). While HTML provides the semantic structure—defining headings, paragraphs, lists, and other content types—CSS controls the visual presentation, telling the browser exactly how to render that content. This separation of concerns is a fundamental principle of modern web development that ensures maintainable, scalable code.

  1. If you completed the previous exercise, index.html should still be open in your code editor, and you can skip the following sidebar. If you closed index.html, re-open it now from the News website folder. We recommend completing the previous exercise (1C) before starting this one, as it establishes the HTML foundation we'll be styling. If you haven't finished it, follow the instructions in the sidebar below.

If You Did Not Complete the Previous Exercise (1C)

  1. Close any files you may have open in your editor.
  2. In your code editor, open index-ready-for-styles.html from the News website folder.
  3. Use File > Save As to save the file as index.html, replacing the older version in your folder.
  • Preview the file in a browser to establish your baseline. In Visual Studio Code with the Live Preview extension (or similar), use Option–B (Mac) or ALT–B (Windows) to open your HTML document in your default browser. This keyboard shortcut streamlines your development workflow by eliminating the need to manually navigate to and open files.

  • Examine the unstyled structure: notice the main heading (h1), three images, and three news stories. Each story contains a subheading (h2) and multiple paragraphs of text. This represents typical browser default styling—functional but visually uninspiring.

  • Understanding Tag Selectors: Establishing Global Design Standards

    Tag selectors are your first tool for creating consistent design patterns across your website. They target all instances of a specific HTML element, effectively setting "default" appearance rules that ensure visual consistency without requiring individual styling of each element.

    1. Return to index.html in your code editor.
    2. CSS operates behind the scenes of your webpage, which is why it belongs in the head section rather than the visible body. The style tag creates an internal stylesheet—perfect for learning and small projects. Add the following code in the head section, immediately below the title tag:

      <title>The Onion—Today's Top Stories</title>
         <style>
      
         </style>
      </head>
    3. CSS selectors are the foundation of targeted styling—they tell the browser precisely which elements to style. The tag selector is the most straightforward type, targeting every instance of a specific HTML tag throughout your document. Add this h1 tag selector inside your <style> tags:

      <style>
         h1 {
      
         }
      </style>

      This rule will apply styling to every h1 element on your page, ensuring consistent header appearance across your entire site.

    4. Within the h1 selector's curly braces, add these property declarations:

      h1 {
         font-family: Arial, Helvetica, sans-serif;
         font-size: 35px;
         color: #006b3a;
      }

      A complete CSS rule consists of a selector (h1) followed by property declarations enclosed in curly braces. Each property declaration pairs a predefined CSS property (like font-size or color) with a specific value (35px, #006b3a). Professional developers format each property on its own indented line—while not required by browsers, this convention dramatically improves code readability and maintenance.

    5. Save the file using Ctrl+S (Windows) or Cmd+S (Mac).

    6. Return to your browser and refresh the page to witness the transformation. The heading styling should now reflect your CSS rules—your first step into the world of web design!

    Understanding the Font-Family Property

    The font-family property functions as a prioritized wish list, known as a font stack. Browsers attempt to use the first font if available on the user's system, falling back to subsequent options only when necessary. This approach ensures your design remains consistent across different devices and operating systems. Always end your font stack with a generic family (like sans-serif) as a final fallback.

    Font Stack Strategy

    The font-family property creates a fallback system. If the first font is unavailable on the user's computer, the browser automatically tries the next font in the list.

    Demystifying Hexadecimal Color Codes

    Hexadecimal color codes provide precise color control in web design. These 6-digit values represent RGB (Red, Green, Blue) color channels: the first pair controls red intensity, the middle pair green, and the final pair blue. Each pair ranges from 00 (no color) to FF (maximum intensity). All hex codes begin with a hash symbol (#). For example, #006b3a creates a professional dark green by combining no red (00), medium green (6b), and low blue (3a). Hex values are case-insensitive, so #00FF33 and #00ff33 are identical.

  • Return to index.html in your code editor to continue building your stylesheet.

  • Below your existing h1 rule, add styling for subheadings by creating an h2 rule. Add only the bold code shown below:

    h1 {
          font-family: Arial, Helvetica, sans-serif;
          font-size: 35px;
          color: #006b3a;
       }
       h2 {
          font-family: Arial, Helvetica, sans-serif;
          font-size: 24px;
          color: #8f6800;
       }
    </style>
  • Save the file and observe how consistent typography creates visual hierarchy.
  • Return to your browser and refresh to see your enhanced heading system in action. Notice how the consistent font family between h1 and h2 creates visual cohesion while the size and color differences establish clear hierarchy.
  • Let's complete the typography foundation by styling paragraph text. Return to your code editor.
  • Below your h2 rule, add comprehensive paragraph styling (add only the bold code):

    h2 {
          font-family: Arial, Helvetica, sans-serif;
          font-size: 24px;
          color: #8f6800;
       }
       p {
          font-family: Verdana, sans-serif;
          font-size: 14px;
          line-height: 25px;
       }
    </style>

    The line-height property controls vertical spacing between lines of text—what print designers call "leading." This property defines the total height allocated to each line of text, with characters vertically centered within that space. Increasing line-height adds breathing room above and below text, dramatically improving readability, especially for longer content blocks. The difference between cramped text (line-height: 1.0) and well-spaced text (like our 25px setting) can mean the difference between content that users scan and content they actually read.

  • Save your work to preserve these critical typography improvements.
  • Return to your browser and refresh the page to see the complete transformation. The combination of thoughtful font choices, appropriate sizing, and optimized line spacing has converted your basic HTML into professionally styled content that's both visually appealing and highly readable.

  • Hexadecimal Color System

    RGB Structure

    Six-digit hex values represent Red, Green, Blue components. First two digits control red, middle two green, last two blue intensity.

    Syntax Requirements

    Hex values must start with a hash symbol. Letters can be uppercase or lowercase without affecting the color output.

    Example Color Values Used

    H1 Green
    6
    H2 Gold
    8

    CSS Typography Units: Choosing the Right Measurement

    In 2026, web typography offers several unit options, each with distinct advantages. Pixels (px) provide absolute control and remain popular for their predictability—what you see is what users get. However, modern responsive design increasingly favors relative units like rem and em for their scalability across devices. Rem units scale relative to the root font size, ensuring consistent proportions, while em units scale relative to their parent element. For beginners, pixels offer the clearest learning path, but understanding relative units becomes crucial as you advance to responsive, accessible design practices.

    Key Takeaways

    1CSS is written in the HTML head section within style tags to control visual presentation separate from content structure
    2Tag selectors target all instances of specific HTML elements, providing consistent default styling across the entire webpage
    3CSS rules consist of selectors and property declarations, with each property-value pair controlling specific visual characteristics
    4Font-family creates a fallback system where browsers automatically try alternative fonts if the primary choice is unavailable
    5Hexadecimal color codes use six-digit values to represent RGB components, starting with a hash symbol and supporting both cases
    6Property declarations should be indented and placed on separate lines for improved code readability and maintenance
    7Line-height controls vertical spacing between text lines, significantly impacting readability especially for longer content
    8Pixels are the recommended starting unit for CSS typography due to their simplicity and direct correlation to screen display

    RELATED ARTICLES