HTML Styles

HTML Tutorial

HTML Styles – Complete Beginner Guide

Styling makes websites beautiful, readable, and user-friendly. Without styles, HTML pages look plain and unstructured.

In HTML, styles are used to control:

  • Colors

  • Fonts

  • Sizes

  • Spacing

  • Alignment

  • Layout

In this beginner-friendly, you’ll learn:

  • What HTML styles are

  • The style attribute

  • Internal CSS

  • External CSS

  • Inline vs internal vs external styling

  • Best practices

  • Common mistakes

Let’s get started


What Are HTML Styles?

HTML styles are used to change the appearance of elements.

Example without style:

With style:

Now the text appears blue.


The style Attribute (Inline CSS)

The simplest way to style HTML is using the style attribute.

Example:

This changes text color to red.


Multiple Styles

You can add multiple properties:

Each property is separated by a semicolon.


Common Style Properties

Here are some common CSS properties used in HTML styles:

PropertyPurpose
colorText color
background-colorBackground color
font-sizeText size
font-familyFont style
text-alignText alignment
borderBorder styling
paddingSpace inside element
marginSpace outside element

Example – Background Color


Example – Font Styling


Internal CSS (Inside <style> Tag)

Instead of adding style to each element, you can use internal CSS.

Now all <p> elements will be green.


External CSS (Best Practice)

The best way to apply styles is using an external CSS file.

Example:

In styles.css:

This keeps HTML clean and maintainable.


Inline vs Internal vs External CSS

MethodWhere UsedRecommended?
Inlinestyle attribute Not for large projects
Internal<style> tagFor small projects
ExternalSeparate fileBest practice

Use external CSS for professional projects.


HTML Styles with Classes

Example:

CSS:

Classes make styling reusable.


HTML Styles with IDs

Example:

CSS:

IDs should be unique.


Real-World Example – Styled Card

CSS:


Styling with CSS Frameworks

Modern frameworks like:

  • Bootstrap

  • Tailwind CSS

Provide ready-made style classes.

Example (Bootstrap):

Example (Tailwind):


Why Avoid Inline Styles?

Inline styles:

  •  Hard to maintain
  •  Hard to override
  • Increase HTML size
  •  Not scalable

Use CSS files instead.


HTML Style Best Practices

  •  Use external CSS
  •  Use meaningful class names
  • Keep styling separate from content
  •  Avoid excessive inline styling
  •  Use consistent spacing

Common Beginner Mistakes

  •  Mixing inline and external CSS
  • Overusing ID selectors
  • Writing duplicate styles
  •  Not organizing CSS properly

Keep styles clean and structured.


Styling and Accessibility

Good styling improves:

  • Readability

  • Contrast

  • User experience

  • Mobile responsiveness

Always ensure proper contrast between text and background.


Frequently Asked Questions (FAQs)

1. What is the style attribute in HTML?

The style attribute is used to apply inline CSS directly to an element.


2. What is the difference between inline and external CSS?

Inline CSS is applied directly in HTML, while external CSS is written in a separate file.


3. Which styling method is best?

External CSS is best for large and professional projects.


4. Can I apply multiple styles in one style attribute?

Yes, separate them with semicolons.


5. Why should I avoid inline styles?

Because they make code harder to maintain and scale.


Conclusion

HTML styles control how your website looks and feels.

You learned:

  • Inline styling

  • Internal CSS

  • External CSS

  • Classes and IDs

  • Best practices

Mastering HTML styles is the first step toward professional web design.

You may also like...