Contents
Basic Concepts
HTML (HyperText Markup Language) is the backbone of every webpage. It’s made up of simple building blocks that help define how content should be shown in a browser. Once you get the hang of the basics, you’ll be able to create clean, structured, and accessible web pages.
HTML Syntax and Structure
HTML uses a tag-based system to tell the browser what each part of the page is. Each element is defined by tags, and most of them have an opening and a closing tag.
Basic HTML Element:
Content goes here
- Opening Tag:
<tagname>
starts the element. - Content: The stuff inside the element (text, images, other HTML elements).
- Closing Tag:
</tagname>
closes the element.
Some elements don’t need a closing tag—they’re self-closing, like an image tag:
Elements and Tags
In HTML, elements are made up of an opening tag, the content, and a closing tag. These elements define things like headings, paragraphs, images, links, and more.
Common HTML Elements:
Headings: Use these for titles or subtitles.
This is a main heading
This is a subheading
- Paragraphs: For blocks of text.
This is a paragraph of text.
- Links (Anchors): To create clickable links to other web pages.
- Images: To display pictures on your page.
Attributes and Values
Attributes are like extra information you give to an element. They’re added inside the opening tag and usually have a name and a value in quotes.
General Attribute Example:
Content
Example with an Image:
src
: Path to the image file.alt
: Text that shows up if the image doesn’t load (or for screen readers).width
andheight
: Set the image size.
Example with a Link:
href
: The URL for the link.target="_blank"
: Opens the link in a new tab.
Common Attributes:
id
: Gives a unique identifier to an element.class
: Assigns a class name for styling or JavaScript use.style
: Adds inline CSS to style an element directly.title
: Provides a tooltip when the user hovers over the element.
HTML Document Structure
An HTML document follows a specific structure to keep things organized and readable by browsers. It has essential elements that define the document and the visible content.
Basic HTML Document Structure:
Basic HTML Structure
Welcome to My Website
This is a basic HTML page.
Breaking it Down:
<!DOCTYPE html>
: Tells the browser this is an HTML5 document.<html>
: The root element that wraps all the content on the page.<head>
: Contains meta-information (like character set and title), links to CSS or scripts, and is invisible on the actual page.<meta charset="UTF-8">
: Sets the character encoding to UTF-8, which supports most languages.<meta name="viewport" content="width=device-width, initial-scale=1.0">
: Helps the page scale correctly on different devices, which is important for responsive design.<title>
: The title that appears in the browser tab and is used by search engines.<body>
: Holds all the content that users see and interact with on the page.
Summary
The basics of HTML start with understanding its syntax and structure. HTML uses elements and tags to define content, while attributes add extra functionality and information. Finally, the HTML document structure organizes everything in a way that browsers can easily read. With these foundational concepts, you can start building web pages that are well-structured, accessible, and functional.