17 Simple HTML Code Examples You Can Learn In 10 Minutes

Even though modern websites are generally built with user-friendly interfaces, it's useful to know some basic HTML. If you know the following 17 HTML example tags (and a few extras), you'll be able to create a basic webpage from scratch or tweak the code created by an app like WordPress.

We've provided simple HTML code examples with output for most of the tags. If you want to test them for yourself, copy the sample HTML code into your own document. You can play around with them in a text editor and load up your file in a browser to see what your changes do. Let's get started!

1. <!DOCTYPE html>

You'll need this tag at the beginning of every HTML document you create. It ensures that the web browser knows that it's reading HTML and that it expects HTML5, the latest version. Even though this isn't actually an HTML tag, it's still an important one to know.

2. <html>

This is another tag that tells a browser that it's reading HTML. The tag goes straight after the DOCTYPE tag, and you close it with a tag right at the end of your file. Everything else in your document goes between these tags.

3. <head>

The tag starts the header section of your file. The stuff that goes in here doesn't appear on your webpage. Instead, it contains metadata for search engines and info for your browser. If you want ads on your site, Google's AdSense code goes here, too.

For basic pages, the tag will contain your title, and that's about it. But there are a few other things that you can include, which we'll go over in a moment.

4. <title>

html title tag
screenshot by andy betts

This tag sets the title of your page. All you need to do is put your title in the tag and close it, like this (we've included the header tags, as well, to show the context):

<head> <title>My Website</title> </head>

That's the name that will be displayed as the tab title when it's opened in a browser.

5. <meta>

Like the title tag, metadata is put in the header area of your page. Metadata is primarily used by search engines and is information about what's on your page. There are several meta fields, but these are some of the most commonly used:

  • description: A basic description of your page.
  • keywords: A selection of keywords applicable to your page (although these are generally ignored by search engines now).
  • author: The author of your page.
  • viewport: A tag for ensuring that your page looks good on all devices.

Here's an example that might apply to this page:

<meta name="description" content="A basic HTML tutorial"> <meta name="keywords" content="HTML,code,tags"> <meta name="author" content="MUO"> <meta name="viewport" content="width=device-width, initial-scale=1.0">

The "viewport" tag should always have "width=device-width, initial-scale=1.0" as the content to make sure your page displays well on mobile and desktop devices.

6. <body>

After you close the header section, you get to the body. You open this with the tag, and close it with the tag. That goes right at the end of your file, just before the

All the content of your webpage goes in between these body tags. It's as simple as it sounds:

<body> Everything you want displayed on your page. </body>

7. <h1> (and Other Header Tags)

The tag defines a level-one header on your page. This will usually be the title, and there will ideally only be one on each page.

defines level-two headers such as section headers,

level-three sub-headers, and so on, down to

. As an example, the names of the tags in this article are level-two headers.

<h1>Big and Important Header</h1> <h2>Slightly Less Big Header</h2> <h3>Sub-Header</h3>

Result:

html header tags
screenshot by andy betts

As you can see, they get smaller at each level. Search engines rank them in order of importance.

8. <p>

The paragraph tag starts a new paragraph. This usually inserts two line breaks.

Look, for example, at the break between the previous line and this one. That's what a

tag will do.

<p>Your first paragraph.</p> <p>Your second paragraph.</p>

Result:

Your first paragraph.

Your second paragraph.

You can also use CSS styles in your paragraph tags, like this one which changes the text size:

<p style="font-size: 150%;">This is 50% larger text.</p>

Result:

make text larger in html
screenshot by andy betts

9. <br>

The line break tag inserts a single line break, with no space between the lines:

<p>The first line. The second line (close to the first one).</p>

Result:

line break in html
screenshot by andy betts

Working in a similar way is the tag. This draws a horizontal line on your page and is good for separating sections of text.

10. <strong>

This tag defines important text. In general, that means it will be bold, although it is possible to use CSS to make text display differently.

However, by default, you can safely use to bold text.

<strong>Very important things you want to say.</strong>

Result:

Very important things you want to say.

If you're familiar with the tag for bolding text, it still works, but is no longer recommended. You should always use the tag instead.

Từ khóa » Html First Codes