How To Write HTML Code - 7 Steps (With Pictures) - Wikihow

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

11/28/2020 How to Write HTML Code: 7 Steps (with Pictures) - wikiHow

Learn why people trust wikiHow

How to Write HTML Code


Co-authored by wikiHow Staff
Last Updated: September 3, 2020 References

HTML stands for HyperText Markup Language. It's one of the most basic programming
languages, primarily used in web design. It may seem a little complicated at first, but it's
actually one of the easier programming languages too learn. This wikiHow teaches you
how to write some basic HTML. Soon, you'll be creating your own gorgeous websites by
hand.

Part
1 Creating and Saving a New HTML Document

Open a text editor. You can use any text editor that came pre-installed on
1 your system to write HTML. On Windows, you can open Notepad. On Mac,
open TextEdit. Use the following steps to open a text editor:
Windows:
Click the Windows Start icon.
Type "Notepad".
Click Notepad.
Mac:
Click the magnifying glass in the upper-right corner.
Type "TextEdit" in the search bar and press Enter.
Click New Document.

Type <!do c type html> at the tip of the page. This tag tells the web
2 browser that the document type is an HTML document.

Click File . It's in the menu bar at the top.


3
Click Save as . It's in the "File" menu.
4
On Mac, simply click Save.

https://www.wikihow.com/Write-HTML-Code 1/9
11/28/2020 How to Write HTML Code: 7 Steps (with Pictures) - wikiHow

Type a name for the document. You will want to create a separate HTML
5 document for each web page of your websites. On many websites, the front
page is titled "index.html", but you can name it anything you want. Enter the file
name you want to name the document next to "File name".

Change the file extension to .htm l . By default, Notepad saves files as


6 ".txt" files, and TextEdit saves files as ".rft" files. Use one of the following
steps to save the document as an HTML document:
PC: Use the drop-down menu next to "Save as type:" and select "All Files
(*,*)". Then manually erase the ".txt" extension at the end fo the file name
and replace it with ".html".
Mac: Click the drop-down menu next to "File format" at the bottom of the
save window. Then click select "Web Page (.html)" in the drop-down menu.
This will add the ".html" extension at the end of the file name automatically

Click Save . This saves the document as an HTML document. From now
7 on, if you need to save your work, just click File followed by Save.

Part
2 Writing the Head and Body

Type <htm l > in the next line. This is the opening tag for your HTML
1 document. This should go in the second line after the "<!doctype html>" tag.
This tag tells the web browser that the following text is in HTML format.

Press ↵ Enter a few times and type </ht m l> . This provides a few
2 blank lines and then adds the closing tag for the opening "<html>" tag.
In HTML, everything has an opening tag and a closing tag. When you create
a new HTML tag, you must always remember to add a closing tag.
Otherwise, it won't work.
The "<html>" should always remain at the top of the document, and the "
</html>" tag should always remain at the bottom of the document. The rest
of your HTML code will go in between these two tags.

Type <hea d > in the third line. This is the opening tag for the HTML
3 Head of the HTML document. The Head contains meta-information that
typically doesn't appear on-screen when people view your website. The opening
tag for the head should go in the line just below the line with the "<html>" tag.[1]

https://www.wikihow.com/Write-HTML-Code 2/9
11/28/2020 How to Write HTML Code: 7 Steps (with Pictures) - wikiHow

It usually contains the document title, templates, links to related pages, and
special coding instructions for the web browser. It can also contain a style
language known as CSS (Cascading Style Sheets).

Press ↵ Enter type <tit l e> . This is the tag that contains the document
4 title. When viewed in a web browser, the title is the text that appears in the
tab at the top. This tag should go just below the opening tag of the Head.

Type a title for the web page. You can type any title you want for your web
5 page. It should come directly after the "<title>" tag, or on the next line.

Type </ti t le> . This is the closing tag for the title tag. This goes after
6 the title in the HTML document. It can be on the same line or separate line.
What's important is that we close the title tag of the HTML document.

Press ↵ Enter and type </he a d> . This tag closes the Head of the HTML
7 document. If you want to add anything else to the Head of the document,
make sure you enter it in between the "<head>" and "</head>" tags. You can
use as many lines as you need.

Type <bod y > after the Head. This is the opening tag for the Body of the
8 HTML document. The body contains visual elements of a web page that
appear in your entire HTML document.
This includes text, images, clickable buttons, links, the background color,
background image, or anything else that appears on-screen when viewing
your website from within a web browser.[2]

Press ↵ Enter twice and type </bo d y> . This provides a space before
9 closing the Body of the HTML document. You can use this space to start
writing the contents of your HTML document. All the contents of your web page
are going to be written in between the "<body>" and "</body>" tags. So far your
entire document should look something like this:

https://www.wikihow.com/Write-HTML-Code 3/9
11/28/2020 How to Write HTML Code: 7 Steps (with Pictures) - wikiHow

<!doctype html>
<html>
<head>
<title>Document title</title>
</head>
<body>

</body>
</html>

Part
3 Writing Text in HTML

Type <h1> in the Body to add a header. All the contents of your HTML
1 document are going to go between the "<body>" and "</body>" tags. The "
<h1>" tag is the opening tag to write a header.
There are six header tags you can use in HTML that are of different sizes. "
<h1>" is the largest header, and "<h6>" is the smallest header. </li

Write a heading after the header tag. The text your write after the "<h1>"
2 tag will appear in a large header format. If you want the title of your page to
appear at the top in large letters, write "<h1>" followed by the title.

Type </h1 > to close the header tag. Unless you want the entire text of
3 your HTML document to appear in the header format, you'll want to close
the header tag. Type "</h1>" after your header text to close the header.

Type <br> to add a line break. If you want to add a space after some
4 text, type "<br>". This creates a break in the text and adds another line. You
can type the "<br>" tag for as many lines as you need. The line break tag is one
of the few HTML tags that doesn't require a closing tag.

Type <p> to add paragraph text. When you want to add paragraph text
5 in HTML, use the "<p>" tag as the opening for the paragraph text.

Type your paragraph text. Any text you type after the "<p>" tag will be
6 formatted as paragraph text. You can add as much text as you need.

https://www.wikihow.com/Write-HTML-Code 4/9
11/28/2020 How to Write HTML Code: 7 Steps (with Pictures) - wikiHow

Type </p> to close the paragraph text. When you are done writing your
7 paragraph text, use the "</p>" tag to close the "<p>" paragraph tag.

Add a stye element to an HTML text tag. If you want to spice up your tag a
8 little, you can type "style=" inside the HTML text tag and then add an HTML
element to style the text. You can add multiple style elements to a tag by
separating them with a semicolon (;).The following are some options you can
use to style your text tags:[3]
Color: To change the color of the text, type "color:[color name];" after
"style=" in the HTML tag. Type the actual name of a color, or a hexadecimal
color code in place of "[color name]". For example, to change the header
color to red, you would type <h1 style="color:red;"> as the opening tag.
Font: To change the text font, type "font-family:[font name];" after "style=" in
the HTML tag. For example, to change the paragraph text to Garamond, you
would type <p style="font-family:garamond;">. It's important to remember
that not all fonts are accessible from any computer. Web safe fonts that you
can use include; Arial, Arial Black, Roboto, Times New Roman, Times,
Courier New, Courier, Verdana, Georgia, Palatino, Garamond, Bookman,
Comic Sans MS, Candara, and Impact.[4]
Text size: To change the size of the text, type "font-size:[size in percent (%)
or pixels (px)];" after "style=" in the HTML tag. For example, if you want to
change the header size to 50 pixels tall, you would type <h1 style="font-
size=50px;>".
Alignment: You can align your text to the left, center, or right, by typing
"text-align:[alignment];" after "style=" in the HTML tag. For example, if you
want your header to be centered at the top of the page, you would type <h1
style="text-align:center;">.

Adding a list. You can add a numbered or bulleted list to your HTML. Use
9 the following steps to add a list to your HTML: [5]
Type "<ol>" to start a numbered list, or "<ul>" to start a bulleted list.
Type "<li>" to create a new listed item.
Use the "<p>" tag to add text for the listed item.
Type the text for the list item.
Type </p> to close the text portion of the listed item.
Type "</li>" to close the listed item tag.
Repeat for all other list items.
Type "</ol>" or "</ul>" to close your list tag at the end of the list.

https://www.wikihow.com/Write-HTML-Code 5/9
11/28/2020 How to Write HTML Code: 7 Steps (with Pictures) - wikiHow

Review your HTML document. It's a good idea to periodically check your
10 work. If you haven't already done so. Go ahead and save your work. Then
right-click the HTML document and select Open with. Select a web browser to
view it in a web browser. So far your entire HTML code should look something
like this:

<!doctype html>
<html>
<head>
<title>Peanut Butter and Jelly Sandwich</title>
</head>
<body>
<h1 style="color:red; align:center;">How to Make a Peanut Butter and
Jelly Sandwich </h1>
<br>
<h2>Ingredients:</h2>
<ul>
<li>Peanut Butter</li>
<li>Jelly</li>
<li>Bread</li>
</ul>
<br>
<p>Smear the peanut butter on the bread and put jelly on top. Then place a
slice of bread on top. Cut it in half</p>

</body>
</html>

Part
4 Adding Other Elements to HTML

Add a color style to the Body background. If you want to change the
1 background color of the body, edit the "<body>" tag to say "<body style="".
Then type "background-color:[color name];" after "style=" Replace "[color name]"
with the name of a color or a hexadecimal color code. For example, if you
wanted to change the background color to black, you would type the body tag as
<body style="background-color:black;">.
https://www.wikihow.com/Write-HTML-Code 6/9
11/28/2020 How to Write HTML Code: 7 Steps (with Pictures) - wikiHow

Alternatively, you can also set a background image in the Body tag. To do
so, type <body style="background-image:[image url]"> as the body tag.
Replace "[image URL]" with the web address or location of the image you
want to use.

Add an image. Type <img src="[image url]"> to add an image to your web
2 page. Replace "[image url]" with the web address of the image. For
example, "<img src="https:\\www.mywebsite.com/image.png">". Image tags do
not need a closing tag.
You can adjust the size of an image by adding "height=" and "width="
followed by the height and width of the image in pixels in the image tag. For
example, "'''<img src="https:\\www.mywebsite.com/image.png" width="500"
height="600">
You can also center an image by typing the opening tag <center> before the
tag, and </center> after the image tag.

Add a link to another web page. Linking back to other web pages is
3 important in web design. Use the following steps to create a link that people
can click to be directed to another web page:
Type <a href= to start the link tag.
Add the URL of the page you want to link to in quotations after "a href=".
Type > to close the opening tag of the link.
Type text you want to use for your link after the opening tag. Alternatively,
you can use an image tag to use an image as a clickable link.
Type </a> to close the HTML link tag. An example, the tag <a
href="https://www.wikihow.com/Create-a-Link-With-Simple-HTML-
Programming">Click here to learn how to link</a> renders Click here to
learn how to link.

Type <hr> to add a horizontal line. A horizontal line can be used as a


4 thematic break in text. To add a horizontal line, simply type <hr>. This tag
does not need a closing tag.

Review your work. Once you've made significant progress on your HTML
5 document, go ahead and save it and view it in a web browser to see what it
looks like. Your HTML code should look something like this:

https://www.wikihow.com/Write-HTML-Code 7/9
11/28/2020 How to Write HTML Code: 7 Steps (with Pictures) - wikiHow

<!doctype html>
<html>
<head>
<title>Document title</title>
</head>
<body style="background-color:black;">
<center>
<img src="https://www.mywebsite.com/logo_banner.png>
<br>
<a href="https://www.mywebsite.com/home><img
src="https://www.mywebsite.com/home_button.jpg>
<a href="https://www.mywebsite.com/page2><img
src="https://www.mywebsite.com/next_button.jpg>
</center>
<br>
<h1 style="color:white;">About Us</ht>
<br>
<p style='color:white;">A little about us...</p>
<hr>
</body>
</html>

Tips

Don't forget to close the tags, otherwise, your text will become one big mess!

Although you can make a fairly good website with plain HTML, it might be a
good idea to learn CSS, as you can decorate your website with it.

Your website looks good, but how much does it actually do? Try learning some
languages like Javascript, Ruby, and PHP to add functionality!

https://www.wikihow.com/Write-HTML-Code 8/9
11/28/2020 How to Write HTML Code: 7 Steps (with Pictures) - wikiHow

Submit a Tip
All tip submissions are carefully reviewed before being published

Your tip here

Submit

References

1. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head
2. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body
3. https://www.w3schools.com/html/html_styles.asp
4. https://websitesetup.org/web-safe-fonts-html-css/
5. https://www.w3schools.com/html/html_lists.asp

https://www.wikihow.com/Write-HTML-Code 9/9

You might also like