Course Content
Introduction to HTML
In this introductory module, you'll learn what HTML is and its role in web development. You will set up your development environment and create your first HTML page. You'll also understand the basic structure of an HTML document and get familiar with fundamental HTML elements and attributes.
0/4
Working with Text in HTML
This module covers how to format text in HTML, including creating headings, paragraphs, and lists. You'll learn how to emphasize text with bold, italics, and underline, and how to create links for navigation. You'll also explore text alignment and introduce inline CSS for basic styling.
0/4
Working with Images and Multimedia
In this module, you’ll learn how to add images and multimedia to your HTML pages. You'll master the <img> tag, and understand how to work with attributes like src and alt. Additionally, you'll discover how to embed audio and video files directly into your webpage, enhancing its interactivity.
0/3
Tables and Forms in HTML
This module introduces the use of tables for displaying structured data and forms for collecting user input. You'll learn how to create, format, and style tables, and how to build forms with input fields, checkboxes, and buttons. Basic HTML5 form validation will also be covered.
0/2
HTML5 Elements and Semantic Markup
Explore the power of HTML5 in this module, where you’ll learn about new HTML5 elements like <article>, <section>, and <nav>. You’ll gain an understanding of semantic HTML, which helps improve search engine optimization (SEO) and accessibility. You’ll also be introduced to HTML5-specific features such as video and audio embedding.
0/3
Advanced HTML Concepts
This module dives deeper into advanced HTML topics, including embedding external content using [iframe], working with HTML5 APIs like geolocation, and implementing accessibility best practices with ARIA attributes. You’ll also get a primer on responsive web design with the use of meta tags and media queries.
0/4
HTML Best Practices
Learn the best practices for writing clean, maintainable, and accessible HTML. This module covers proper code formatting, the importance of semantic HTML, and how to structure your HTML for SEO. You’ll also get practical tips on debugging HTML and using online validators to ensure your code is error-free.
0/3
Project – Building a Simple Website
Apply everything you’ve learned by creating a complete website from scratch in this hands-on project. You’ll plan, design, and build a multi-page website, incorporating text, images, forms, and navigation. This project will help you solidify your skills and showcase your work.
0/4
Conclusion and Next Steps
In the final module, you'll review the key concepts and skills you’ve learned throughout the course. You’ll also get guidance on the next steps in your web development journey, including an introduction to CSS for styling and JavaScript for interactivity. You’ll complete a final assessment to demonstrate your new HTML skills.
0/2
Complete HTML Course (Free)
About Lesson

Text Alignment and Styles

This lesson covers how to align and style text using HTML and CSS. You’ll learn how to control text positioning, apply colors, and customize fonts for an engaging user experience.


1. What is Text Alignment?

Text alignment determines how text is positioned horizontally within its container. HTML doesn’t directly support text alignment but allows it through CSS.

Common Text Alignment Options:

  • Left: Default alignment.
  • Right: Aligns text to the right edge.
  • Center: Aligns text in the middle of the container.
  • Justify: Aligns text evenly along both edges.

2. Aligning Text with CSS

Use the text-align property in CSS to control alignment.

Syntax:

text-align: value;

Examples:

  • Left Alignment:
    text-align: left;
    
  • Right Alignment:
    text-align: right;
    
  • Center Alignment:
    text-align: center;
    
  • Justify Alignment:
    text-align: justify;
    

HTML Example:

<!DOCTYPE html>
<html>
<head>
    <style>
        .left { text-align: left; }
        .right { text-align: right; }
        .center { text-align: center; }
        .justify { text-align: justify; }
    </style>
</head>
<body>
    <h1 class="center">Text Alignment Example</h1>
    <p class="left">This text is aligned to the left.</p>
    <p class="right">This text is aligned to the right.</p>
    <p class="center">This text is centered.</p>
    <p class="justify">This text is justified. It spreads the text so that it aligns with both the left and right margins, creating a clean look.</p>
</body>
</html>

3. Text Styling with CSS

Text styling enhances the visual appeal of your content by modifying properties such as font, size, color, and spacing.


4. Common Text Styling Properties

  1. Font Family:

    • Changes the font style.
    • Syntax:
      font-family: "Font Name", fallback-font;
      
    • Example:
      font-family: "Arial", sans-serif;
      
  2. Font Size:

    • Adjusts the size of the text.
    • Syntax:
      font-size: value;
      
    • Example:
      font-size: 16px;
      
  3. Font Color:

    • Changes the color of the text.
    • Syntax:
      color: value;
      
    • Example:
      color: #333333; /* Hexadecimal color */
      
  4. Font Weight:

    • Defines the thickness of the text.
    • Syntax:
      font-weight: value;
      
    • Example:
      font-weight: bold;
      
  5. Font Style:

    • Sets the style of the text (e.g., normal, italic).
    • Syntax:
      font-style: value;
      
    • Example:
      font-style: italic;
      
  6. Text Transform:

    • Modifies text capitalization.
    • Syntax:
      text-transform: value;
      
    • Example:
      text-transform: uppercase;
      
  7. Text Decoration:

    • Adds or removes underline, overline, or strikethrough.
    • Syntax:
      text-decoration: value;
      
    • Example:
      text-decoration: underline;
      
  8. Letter Spacing and Line Height:

    • Letter Spacing: Adjusts the spacing between letters.
      letter-spacing: 2px;
      
    • Line Height: Adjusts the spacing between lines of text.
      line-height: 1.5;
      

5. Example: Combining Text Alignment and Styling

<!DOCTYPE html>
<html>
<head>
    <title>Text Alignment and Styles</title>
    <style>
        body {
            font-family: "Arial", sans-serif;
        }
        .title {
            text-align: center;
            font-size: 24px;
            font-weight: bold;
            color: #2a9d8f;
        }
        .paragraph {
            text-align: justify;
            font-size: 16px;
            line-height: 1.6;
            color: #264653;
        }
        .highlight {
            text-decoration: underline;
            font-style: italic;
        }
    </style>
</head>
<body>
    <h1 class="title">Text Alignment and Styling Example</h1>
    <p class="paragraph">Text alignment and styling are essential for creating visually appealing content. Proper use of <span class="highlight">alignment</span> and styles improves readability and user engagement.</p>
</body>
</html>

6. Hands-On Activity: Applying Alignment and Styles

  1. Open your text editor and create a file called text_styles.html.
  2. Use the code above to explore various alignment and styling options.
  3. Experiment by changing colors, fonts, and alignment values.

7. Best Practices for Text Alignment and Styles

  1. Choose Readable Fonts:

    • Use sans-serif fonts for body text and decorative fonts sparingly.
  2. Maintain Consistency:

    • Keep font sizes and styles consistent across pages for a professional look.
  3. Enhance Contrast:

    • Use high contrast between text color and background for readability.
  4. Align for Content Type:

    • Use justified or centered text for short content like titles; left alignment is better for paragraphs.
  5. Avoid Over-Styling:

    • Use text effects like bold and italic sparingly to prevent clutter.

8. Summary

  • Text alignment (text-align) controls horizontal positioning.
  • CSS provides powerful tools for text styling, including font customization, color, and spacing.
  • Combining alignment and styles creates a visually balanced and readable design.