Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST

HTML and CSS Essentials


HTML & CSS: Essentials

Learn the core building blocks: HTML elements, attributes, and how CSS hooks onto them to control presentation.


HTML element anatomy

Every element has an opening tag, optional content, and a closing tag.

The browser reads this tree (called the DOM) to render the page.

Example

<p class="lead" title="Intro">Hello world</p>
Try it Yourself »
  • Tag name: p defines a paragraph.
  • Attributes: class and title supply metadata.
  • Content: Inner text that users see.

If you want to read more or get an in-depth understanding, see HTML Elements and HTML Attributes in the HTML tutorial.


Global attributes you will use everywhere

  • class - groups elements for CSS styling.
  • id - unique identifier for one element (useful for anchors and scripting).
  • title - tooltip text.
  • lang - language of a document or element (<html lang="en">).
  • data-* - custom data attributes for scripts or styling hooks.

Reference: HTML Global Attributes.



How CSS attaches to HTML

Use selectors based on tag, class, or id to style the markup.

Inline styles work, but external stylesheets keep projects maintainable.

Note: Selectors are words that tell CSS which HTML element to style, for example .card for any element with class="card".

HTML + CSS

<article class="card" id="intro">
  <h2>Welcome</h2>
  <p>Learning HTML and CSS together unlocks creative freedom.</p>
</article>
.card {
  border: 1px solid #dde4f0;
  padding: 24px;
  border-radius: 12px;
  background: #fff;
}
#intro h2 {
  color: #04AA6D;
}
Try it Yourself »

If you want to read more or get an in-depth understanding, see CSS Syntax and How To Add CSS in the CSS tutorial.


Semantic structure matters

Prefer semantic tags (<header>, <nav>, <main>, <section>, <footer>) over generic <div>s.

They help screen readers and search engines understand the page.

Check HTML Semantics for full definitions.


Block vs inline

  • Block elements (e.g., <div>, <section>, <p>) span full width and start on a new line.
  • Inline elements (e.g., <span>, <a>, <strong>) only take necessary width.

This distinction affects layout and is crucial when applying CSS display rules.

If you want to read more about HTML Block & Inline or get an in-depth understanding, go to HTML Block & Inline in the HTML tutorial.


Whitespace and indentation

Indent child elements consistently to visualize hierarchy.

Browsers ignore extra whitespace, but it makes code easier to read for us humans.

<main>
  <section>
    <h2>Headline</h2>
    <p>Supporting text.</p>
  </section>
</main>


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.