







HTML can look a little frightening at first, with its angle brackets and unfamiliar short words in rows. But what happens inside is simpler than it seems. HTML attaches small marks before and after a sentence to say, “From here on, this is a title,” or “This part is one paragraph.” The basic grammar of HTML is made of marks that wrap around writing, and small explanations added to those marks.
These marks are usually called “tags.” You don't need to memorize them as hard words from the start. Just as you stick a label on a gift box saying who it's for and what's inside, think of a tag as a label that tells what job a piece of writing does. Some tags wrap the front and back of the text together, and some do their work alone, once. And when needed, you can write extra information into a tag, so that text with the same role can be described a little more precisely.
1.We look at how tags attach to the front and back of text and what role they play.
2.We see why a mark that announces the start and a mark that announces the end are needed together.
3.We think about when a tag that finishes its work alone is used.
4.We understand what extra explanation attributes and values add to a tag.
Picture an editor jotting pencil notes on a book manuscript: “Subheading starts here,” “This sentence is a quotation,” “These lines are a list.” Thanks to those notes, each part can be arranged properly when the book is made later. HTML tags are similar. They leave marks so that a web browser, as it reads the text, can tell which part is a title and which part is an ordinary sentence.
A tag usually looks like a short name written inside angle brackets. For example, `〈p〉` can be thought of as the mark that says a paragraph begins. Here the p is the first letter of the English word “paragraph,” but for now it is enough to remember it simply as the “paragraph mark.” A tag's name tells the computer the role of the text, and shows the reader a screen arranged to match that role.
What matters when reading HTML is not interpreting each word, but seeing which text a mark points to. When you meet the mark `〈h1〉`, understand it as “this is the place for a big title.” When you meet `〈p〉`, read it as “from here on is a paragraph holding one thought.” HTML mixes letters and marks, but what is actually handed to the reader is always the content inside.
The Easiest Way to Look at Tags
A tag is a small role label that tells what a piece of text is.
The short name inside the angle brackets points to the nature of the text, such as title, paragraph or image.
The browser reads tags and shows the content in a form that is easy for readers to recognize.
The meaning of the text a tag wraps or points to matters more than the tag itself.
Many tags mark both the start and the end of a piece of text. For instance, you write `〈p〉` at the start of a paragraph and `〈/p〉` at its end. The slash in the second mark means “the paragraph ends here.” The sentence between them is bound into one paragraph, so the browser can show it as a paragraph.
Picture the notation `〈p〉I opened the window today.〈/p〉`. The `〈p〉` at the very front is the tag that opens the paragraph, and the `〈/p〉` at the very end is the tag that closes it. Between the two marks goes the actual sentence the reader will read. Just as the first and last pages enclose the contents when you open a chapter of a book, the opening and closing tags tell you how far one chunk extends.
The names of the opening and closing tags must be the same. If you began with `〈p〉`, you must finish with `〈/p〉`, and if you began with `〈h1〉` for a title, you must end with `〈/h1〉`. Just as the divisions of a document blur when you close a bookmark somewhere else, a browser can also get confused about the text's boundaries when the pairs don't match. At first, learning only this one promise, if you open it, you close it with the same name, makes HTML far more familiar.
A tag can also hold smaller tags inside it. Think of how a chapter of a book holds many paragraphs, and one paragraph holds a single sentence you especially want to stress. In that case, it is best to keep the order of closing the mark opened last first. It is like opening a box, putting things in, and closing the small box before the big one. When this order is kept, HTML conveys the relationships in the text clearly.
The Promise of Tags That Move in Pairs
An opening tag tells you that text with a certain role is beginning.
A closing tag puts a slash before the name to tell you that role has ended.
If you started with a name, you must close with the same name.
When tags are nested in layers, close the one opened innermost first.
Not every tag has to wrap a sentence from front and back. Some hold no text between them and do one job right where they stand. Marks that place a photo in a document, draw a line between paragraphs, or push text on to the next line are like this. Instead of two marks that open and close, such a tag says alone, “Please place this here.”
For example, the image tag tells where to fetch a photo from. The photo itself does not go between tags. Rather, the tag points to where the photo is, and the browser fetches it and shows it. That is why the extra information “Which photo should we show?” is especially important for the image tag. This extra information is written as an attribute and a value, which we will look at next.
The mark that breaks a line, or the mark that inserts a dividing line, works the same way. It does not wrap a long stretch of text, but places one small change in the flow of the document. A tag that stands alone may seem like an exception to memorize, but it is easier to understand as a single action with no text to hold. The reason there is one tag instead of two is that this mark has nothing to wrap from front and back.
If a tag is the big label that says, “This is a photo,” an attribute is the detailed note written under that label. For example, when you put in a photo, you need information such as where the photo is and what explanation to give people who cannot see it. Attributes fill in what the tag's basic role alone cannot cover.
An attribute is written inside the opening tag, after the tag name. Look at the form `〈img src="garden.jpg" alt="A small potted plant by the window"〉`. Here `img` is the tag that places an image, and `src` and `alt` are extra notes about that image. On the right of each equals sign, `"garden.jpg"` and `"A small potted plant by the window"` are the actual contents of each note. In harder terms these are called values, but you can also simply understand them as the answers you fill into an attribute.
`src` tells which photo to fetch, and `alt` is the place for a short description to give in its stead when the photo cannot be seen. Rather than writing only the photo's exact name, it is kinder to explain what meaning the photo carries within the text. For example, if you write “a red umbrella leaning by the window on a rainy day” rather than “image1,” a reader using a screen reader can imagine the scene too.
Attributes are not only for images. A link that leads to another text can state where it goes, and text you want to set apart can be given a name so that styling can be added later. At first, though, you needn't try to add lots of information to every tag. It keeps a document cleaner to choose the tag's basic role first, and then write only the notes truly needed to make that role more precise.
A Small Formula for Understanding Attributes and Values
A tag states the big role, and an attribute adds the detailed information that role needs.
An attribute is usually written after the tag name, in the form `name="content"`.
The content on the right of the equals sign is the answer to the question the attribute asks, and it is called a value.
A good attribute helps not only machines but also readers who use the screen in other ways.
HTML's grammar seems to hold many small promises. You match opening and closing tags, write the needed information in a lone tag, and put an equals sign between an attribute and its content. But these promises are not rules meant to give the computer an exam. They are a courtesy, so that browsers and other tools can read the structure of a human-written document without misunderstanding.
When you are first writing marks, it is natural to leave one out or mix up the order of closing. At those times, just reread the document and ask, “Where does this sentence begin and where does it end?” and “What does this photo show?” Fixing HTML grammar is closer to editing, checking whether a manuscript's marks and notes are in their places, than to cracking a code.
In the end, HTML's basic grammar comes back to three ideas. You tell the role of text with a tag, you mark both the start and the end for text that is wrapped, and you add any further information with attributes and values. Once you understand these promises, even the strange angle brackets slowly begin to read as the voice of the document.
Key Takeaways
A tag is a mark that tells the role of text and elements, such as title, paragraph or image.
Many tags come as a pair of opening and closing tags that wrap the content between them.
A lone tag, like an image or a line break, does one job without any text to hold.
An attribute is an extra note a tag needs, and a value is the concrete content filled into that note.
