Editors: Write HTML Using Notepad or Textedit
Editors: Write HTML Using Notepad or Textedit
Adobe Dreamweaver
Microsoft Expression Web
CoffeeCup HTML Editor
However, for learning HTML we recommend a text editor like Notepad (PC) or TextEdit (Mac).
We believe using a simple text editor is a good way to learn HTML.
Follow the 4 steps below to create your first web page with Notepad.
Example
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
HTML Documents
All HTML documents must start with a type declaration: <!DOCTYPE html>.
The HTML document itself begins with <html> and ends with </html>.
The visible part of the HTML document is between <body> and </body>.
Example
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
HTML Headings
HTML headings are defined with the <h1> to <h6> tags:
Example
<h1>This is a heading</h1>
<h2>This is a heading</h2>
<h3>This is a heading</h3>
HTML Paragraphs
HTML paragraphs are defined with the <p> tag:
Example
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
HTML Links
HTML links are defined with the <a> tag:
Example
<a href="http://www.w3schools.com">This is a link</a>
HTML Images
HTML images are defined with the <img> tag.
The source file (src), alternative text (alt), and size (width and height) are provided as
attributes:
Example
<img src="w3schools.jpg" alt="W3Schools.com" width="104" height="142">
HTML Elements
HTML documents are made up by HTML elements.
HTML Elements
HTML elements are written with a start tag, with an end tag, with the content in between:
<tagname>content</tagname>
The HTML element is everything from the start tag to the end tag:
Element content
My First Heading
My first paragraph.
End tag
</h1>
</p>
Example
<!DOCTYPE html>
<html>
<body>
Example
<html>
<body>
<p>This is a paragraph
<p>This is a paragraph
</body>
</html>
The example above works in all browsers, because the closing tag is considered optional.
Never rely on this. It might produce unexpected results and/or errors if you forget the end
tag.
HTML Attributes
Attributes provide additional information about HTML elements.
HTML Attributes
Example
<!DOCTYPE html>
<html lang="en-US">
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
The first two letters specify the language (en). If there is a dialect, use two more letters
(US).
Example
<p title="About W3Schools">
W3Schools is a web developer's site.
It provides tutorials and references covering
many aspects of web programming,
including HTML, CSS, JavaScript, XML, SQL, PHP, ASP, etc.
</p>
When you move the mouse over the element, the title will be displayed as a tooltip.
Example
<a href="http://www.w3schools.com">This is a link</a>
You will learn more about links and the <a> tag later in this tutorial.
Size Attributes
Example
<img src="w3schools.jpg" width="104" height="142">
The image size is specified in pixels: width="104" means 104 screen pixels wide.
You will learn more about images and the <img> tag later in this tutorial.
Example
<img src="w3schools.jpg" alt="W3Schools.com" width="104" height="142">
Example
<a href=http://www.w3schools.com>
W3C recommends quotes in HTML4, and demands quotes for stricter document types like
XHTML.
Sometimes it is necessary to use quotes. This will not display correctly, because it contains
a space:
Example
<p title=About W3Schools>
Using quotes are the most common. Omitting quotes can produce errors.
At W3Schools we always use quotes around attribute values.
Example
<p title='John "ShotGun" Nelson'>
Or vice versa:
Example
<p title="John 'ShotGun' Nelson">
HTML Attributes
Below is an alphabetical list of some attributes often used in HTML:
Attribute
alt
disabled
href
id
src
style
title
value
Specifies
Specifies
Specifies
Specifies
Specifies
Specifies
Specifies
Specifies
Description
an alternative text for an image
that an input element should be disabled
the URL (web address) for a link
a unique id for an element
the URL (web address) for an image
an inline CSS style for an element
extra information about an element (displayed as a tool tip)
the value (text content) for an input element.
A complete list, of all legal attributes for each HTML element, is listed in our: HTML Tag
Reference.
HTML Headings
Headings are important in HTML documents.
HTML Headings
Headings are defined with the <h1> to <h6> tags.
<h1> defines the most important heading. <h6> defines the least important heading.
Example
<h1>This is a heading</h1>
<h2>This is a heading</h2>
<h3>This is a heading</h3>
Note: Browsers automatically add some empty space (a margin) before and after each
heading.
Example
<p>This is a paragraph.</p>
<hr>
<p>This is a paragraph.</p>
<hr>
<p>This is a paragraph.</p>
Example
<!DOCTYPE html>
<html>
<head>
<title>My First HTML</title>
<meta charset="UTF-8">
</head>
<body>
.
.
.
Try it Yourself
Meta data means data about data. HTML meta data is data about the HTML
document.
Description
Defines
Defines
Defines
Defines
Defines
an HTML document
the document's body
the document's head Element
HTML headings
a horizontal line
HTML Paragraphs
HTML documents are divided into paragraphs.
HTML Paragraphs
The HTML <p> element defines a paragraph.
Example
<p>This is a paragraph</p>
<p>This is another paragraph</p>
HTML Display
You cannot be sure how HTML will be displayed.
Large or small screens, and resized windows will create different results.
With HTML, you cannot change the output by adding extra spaces or extra lines in your HTML
code.
The browser will remove extra spaces and extra lines when the page is displayed.
Any number of spaces, and any number of new lines, count as only one space.
Example
<p>
This paragraph
Example
<p>This is a paragraph
<p>This is another paragraph
The example above will work in most browsers, but don't rely on it.
Forgetting the end tag can produce unexpected results or errors.
Stricter versions of HTML, like XHTML, do not allow you to skip the end tag.
Example
<p>This is<br>a para<br>graph with line breaks</p>
The <br> element is an empty HTML element. It has no end tag.
Example
<p>This will display as a poem:</p>
<pre>
My Bonnie lies over the ocean.
My Bonnie lies over the sea.
My Bonnie lies over the ocean.
Oh, bring back my Bonnie to me.
</pre>
Description
Defines a paragraph
Inserts a single line break
Defines pre-formatted text
superscript
Example
<p>This text is normal.</p>
<p><b>This text is bold</b>.</p>
The HTML <strong> element defines strong text, with added semantic importance.
Example
<p>This text is normal.</p>
<p><strong>This text is bold</strong>.</p>
Example
<p>This text is normal.</p>
<p><i>This text is italic</i>.</p>
The HTML <em> element defines emphasized text, with added semantic importance.
Example
<p>This text is normal.</p>
<p><em>This text is emphasized</em>.</p>
Browsers display <strong> as <b>, and <em> as <i>.
However, there is a difference in the meaning of these tags: <b> and <i> defines bold
and italic text,
but <strong> and <em> means that the text is "important".
Example
<h2>HTML <mark>Marked</mark> Formatting</h2>
Example
<p>My favorite color is <del>blue</del> red.</p>
Example
<p>My favorite <ins>color</ins> is red.</p>
HTML
Subscript
Formatting
Example
<p>This is <sub>subscripted</sub> text.</p>
HTML
Superscript
Formatting
Example
<p>This is <sup>superscripte</sup> text.</p>
Defines
Defines
Defines
Defines
Defines
Defines
Defines
Defines
Defines
Defines
HTML Styles
Description
bold text
emphasized text
a part of text in an alternate voice or mood
smaller text
important text
subscripted text
superscripted text
inserted text
deleted text
marked/highlighted text
I am Red
I am Blue
HTML Formatting Elements
In the previous chapter, you learned about HTML formatting elements.
Formatting elements are special HTML elements with a special meaning.
Formatting elements were designed to display special types of text, like
important text, emphasized text, subscripts, and superscripts.
HTML Styling
HTML styling has nothing to do with formatting elements.
Styling is about changing or adding the style of existing HTML
elements.
Every HTML element has a default style (background color is white, text
color is black ...)
Changing the default style of an HTML element, can be done with the
style attribute.
Example
<body style="background-color:lightgrey">
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
The bgcolor attribute, supported in older versions of HTML, is not valid in HTML5.
Example
<!DOCTYPE html>
<html>
<body>
<h1 style="color:blue">This is a heading</h1>
<p style="color:red">This is a paragraph.</p>
</body>
</html>
Example
<!DOCTYPE html>
<html>
<body>
<h1 style="font-family:verdana">This is a heading</h1>
<p style="font-family:courier">This is a paragraph.</p>
</body>
</html>
Example
<!DOCTYPE html>
<html>
<body>
Example
<!DOCTYPE html>
<html>
<body>
<h1 style="text-align:center">Centered Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Tthe <center> tag, supported in older versions of HTML, is not valid in HTML5.
Chapter Summary
Example
<p>WWF's goal is to: <q>Build a future where people live in harmony with
nature.</q></p>
Example
<p>Here is a quote from WWF's website:</p>
<blockquote cite="http://www.worldwildlife.org/who/index.html">
For 50 years, WWF has been protecting the future of nature.
The world's leading conservation organization,
WWF works in 100 countries and is supported by
1.2 million members in the United States and
close to 5 million globally.
</blockquote>
Defines
Defines
Defines
Defines
Defines
Defines
Defines
Description
an abbreviation or acronym
contact information for the author/owner of a document
the text direction
a section that is quoted from another source
an inline (short) quotation
the title of a work
a definition termd
Example
<!DOCTYPE html>
<html>
<head>
<style>
body {background-color:lightgray}
h1
{color:blue}
p
{color:green}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Try it Yourself
You can learn much more about CSS in our CSS Tutorial.
CSS Syntax
CSS styling has the following syntax:
element { property:value ; propety:value }
The element is an HTML element name. The property is a CSS property. The value is a
CSS value.
Multiple styles are separated with semicolon.
Inline styling is useful for applying a unique style to a single HTML element:
Inline styling uses the style attribute.
This line styling changes the text color and the left margin of single paragraph:
Example
<h1 style="color:blue">This is a Blue Heading</h1>
Try it Yourself
Example
<!DOCTYPE html>
<html>
<head>
<style>
body {background-color:lightgrey}
h1
{color:blue}
p
{color:green}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Try it Yourself
Example
<DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Try it Yourself
CSS Fonts
The CSS property color defines the text color to be used for an HTML element.
The CSS property font-family defines the font to be used for an HTML element.
The CSS property font-size defines the text size to be used for an HTML element.
Example
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color:blue;
font-family:verdana;
font-size:300%;
}
p {
color:red;
font-family:courier;
font-size:160%
}
</style>
</head>
<html>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Try it Yourself
The <font> tag, supported in older versions of HTML, is not valid in HTML5.
Every visible HTML element has a box around it, even if you cannot see it.
The CSS border property defines a visible border around an HTML element:
Example
p {
border:1px solid black;
}
Try it Yourself
The CSS padding property defines a padding (space) inside the border:
Example
p {
border:1px solid black;
padding:10px;
}
Try it Yourself
The CSS margin property defines a margin (space) outside the border:
Example
p {
border:1px solid black;
padding:10px;
margin:30px;
}
Try it Yourself
The CSS examples above use px to define sizes in pixels (screen pixels).
The id Attribute
All the examples above use CSS to style HTML elements in a general way.
The CSS styles define an equal style for all equal elements.
To define a special style for a special element, first add an id attribute to the element:
Example
<p id="p01">I am different</p>
then define a different style for the (identified) element:
Example
p#p01 {
color:blue;
}
Try it Yourself
Example
<p class="error">I am different</p>
Now you can define a different style for this type (class) of element:
Example
p.error {
color:red;
}
Tr <!DOCTYPE html>
<html>
<style>
p.error {
color: red;
text-align:center
}
h1.error {
color: blue;
}
</style>
<body>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p class="error">I am different.</p>
<p>This is a paragraph.</p>
<h1 class="error">I am different.</h1>
</body>
</html>
Chapter Summary
Use
Use
Use
Use
Use
Use
Use
Use
Use
Use
the
the
the
the
the
the
the
the
the
the
HTML Links
Previous
Next Chapter
Links are found in nearly all web pages. Links allow users to click their way from page to
page.
Link Syntax:
<a href="url">link text</a>
Example:
<a href="http://www.w3schools.com/html/">Visit our HTML tutorial</a>
Try it Yourself
The link text does not have to be text. It can be an HTML image or any other HTML
element.
Local Links
The example above used an absolute URL (A full web address).
A local link (link to the same web site) is specified with a relative URL (without
http://www....).
Example:
<a href="html_images.asp">HTML Images</a>
Try it Yourself
Example
<style>
a:link {color:#000000; background-color:transparent}
a:visited {color:#000000; background-color:transparent}
a:hover
{color:#ff0000; background-color:transparent}
a:active {color:#ff0000; background-color:transparent}
</style>
Try it Yourself
Example
<a href="http://www.w3schools.com/" target="_blank">Visit W3Schools!</a>
Try it Yourself
Target Value
_blank
Description
Opens the linked document in a new window or tab
_self
Opens the linked document in the same frame as it was clicked (this is
default)
_parent
_top
framename
If your webpage is locked in a frame, you can use target="_top" to break out of the frame:
Example
<a href="http://www.w3schools.com/html/" target="_top">HTML5 tutorial!</a>
Try it Yourself
Example
<a href="default.asp">
<img src="smiley.gif" alt="HTML tutorial" style="width:42px;height:42px;border:0">
</a>
Try it Yourself
border:0 is added to prevent IE9 (and earlier) from displaying a border around the
image.
Example
Add an id attribute to any <a> element:
<a id="tips">Useful Tips Section</a>
Try it Yourself
Without a trailing slash on subfolder addresses, you might generate two requests to
the server.
Many servers will automatically add a slash to the address, and then create a new
request.
HTML Images
Previous
Next Chapter
Example
GIF Images
JPG Images
PNG Images
<!DOCTYPE html>
<html>
<body>
<h2>Spectacular Mountains</h2>
<img src="pic_mountain.jpg" alt="Mountain View" style="width:304px;height:228px">
</body>
</html>
Try it Yourself
Always specify image size. If the size is unknown, the page will flicker while the image
loads.
Example
<img src="html5.gif" alt="The official HTML5 Icon">
The alt attribute is required. A web page will not validate correctly without it.
Screen readers are used by people who are blind, visually impaired, or learning disabled.
Example
<img src="html5.gif" alt="HTML5 Icon" style="width:128px;height:128px">
Try it Yourself
Example
<img src="html5.gif" alt="HTML5 Icon" width="128" height="128">
Try it Yourself
Example
<!DOCTYPE html>
<html>
<head>
<style>
img { width:100%; }
</style>
</head>
<body>
Try it Yourself
Example
<img src="/images/html5.gif" alt="HTML5 Icon" style="width:128px;height:128px">
Try it Yourself
Example
<img src="wrongname.gif" alt="HTML5 Icon" style="width:128px;height:128px">
Try it Yourself
Example
<img src="http://www.w3schools.com/images/w3schools_green.jpg">
Try it Yourself
Moving Images
The GIF standard allows moving images:
Example
<img src="programming.gif" alt="Computer Man" style="width:48px;height:48px">
Try it Yourself
Note that the syntax of inserting moving images is no different from non-moving images.
Example
<a href="default.asp">
<img src="smiley.gif" alt="HTML tutorial" style="width:42px;height:42px;border:0">
</a>
Try it Yourself
We have added border:0 to prevent IE9 (and earlier) from displaying a border around
the image.
Image Maps
For an image, you can create an image map, with clickable areas:
Example
<img src="planets.gif" alt="Planets" usemap="#planetmap"
style="width:145px;height:126px">
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" alt="Sun" href="sun.htm">
<area shape="circle" coords="90,58,3" alt="Mercury" href="mercur.htm">
<area shape="circle" coords="124,58,8" alt="Venus" href="venus.htm">
</map>
Try it Yourself
Image Floating
You can let an image float to the left or right of a paragraph:
Example
<p>
<img src="smiley.gif" alt="Smiley face" style="float:left;width:42px;height:42px">
A paragraph with an image. The image floats to the left of the text.
</p>
Try it Yourself
HTML Layouts
Previous
Next Chapter
City Gallery
London
Paris
Tokyo
London
London is the capital city of England. It is the most populous city in the United Kingdom, with
a metropolitan area of over 13 million inhabitants.
Standing on the River Thames, London has been a major settlement for two millennia, its
history going back to its founding by the Romans, who named it Londinium.
Copyright W3Schools.com
Example
<body>
<div id="header">
<h1>City Gallery</h1>
</div>
<div id="nav">
London<br>
Paris<br>
Tokyo<br>
</div>
<div id="section">
<h1>London</h1>
<p>
London is the capital city of England. It is the most populous city in the United
Kingdom,
with a metropolitan area of over 13 million inhabitants.
</p>
<p>
Standing on the River Thames, London has been a major settlement for two millennia,
its history going back to its founding by the Romans, who named it Londinium.
</p>
</div>
<div id="footer">
Copyright W3Schools.com
</div>
</body>
Try it yourself
The CSS:
<style>
#header {
background-color:black;
color:white;
text-align:center;
padding:5px;
}
#nav {
line-height:30px;
background-color:#eeeeee;
height:300px;
width:100px;
float:left;
padding:5px;
}
#section {
width:350px;
float:left;
padding:10px;
}
#footer {
background-color:black;
color:white;
clear:both;
text-align:center;
padding:5px;
}
</style>
nav
section
article
aside
footer
details
This example uses <header>, <nav>, <section>, and <footer> to create a multiple column
layout:
Example
<body>
<header>
<h1>City Gallery</h1>
</header>
<nav>
London<br>
Paris<br>
Tokyo<br>
</nav>
<section>
<h1>London</h1>
<p>
London is the capital city of England. It is the most populous city in the United
Kingdom,
with a metropolitan area of over 13 million inhabitants.
</p>
<p>
Standing on the River Thames, London has been a major settlement for two millennia,
its history going back to its founding by the Romans, who named it Londinium.
</p>
</section>
<footer>
Copyright W3Schools.com
</footer>
</body>
Try it yourself
The CSS
<style>
header {
background-color:black;
color:white;
text-align:center;
padding:5px;
}
nav {
line-height:30px;
background-color:#eeeeee;
height:300px;
width:100px;
float:left;
padding:5px;
}
section {
width:350px;
float:left;
padding:10px;
}
footer {
background-color:black;
color:white;
clear:both;
text-align:center;
padding:5px;
}
Layout can be achieved using the <table> element, because table elements can be styled
with CSS:
Example
<body>
<table class="lamp">
<tr>
<th>
<img src="/images/lamp.jpg" alt="Note" style="height:32px;width:32px">
</th>
<td>
The table element was not designed to be a layout tool.
</td>
</tr>
</table>
</body>
Try it yourself
The CSS
<style>
table.lamp {
width:100%;
border:1px solid #d4d4d4;
}
table.lamp th, td {
padding:10px;
}
table.lamp td {
width:40px;
}
</style>
HTML Tables
Previous
Next Chapter
First Name
Last Name
Points
Eve
Jackson
94
John
Doe
80
Adam
Johnson
67
Jill
Smith
50
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
Try it Yourself
Example explained:
Tables are defined with the <table> tag.
Tables are divided into table rows with the <tr> tag.
Table rows are divided into table data with the <td> tag.
A table row can also be divided into table headings with the <th> tag.
Example
<table border="1" style="width:100%">
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
Try it Yourself
The border attribute is on its way out of the HTML standard! It is better to use CSS.
Example
table, th, td {
border: 1px solid black;
}
Try it Yourself
Remember to define borders for both the table and the table cells.
Example
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
Try it Yourself
Example
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th,td {
padding: 15px;
}
Try it Yourself
Example
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Points</th>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
Try it Yourself
Example
th {
text-align: left;
}
Try it Yourself
Example
table {
border-spacing: 5px;
}
Try it Yourself
Example
<table style="width:100%">
<tr>
<th>Name</th>
<th colspan="2">Telephone</th>
</tr>
<tr>
<td>Bill Gates</td>
<td>555 77 854</td>
<td>555 77 855</td>
</tr>
</table>
Try it Yourself
Example
<table style="width:100%">
<tr>
<th>First Name:</th>
<td>Bill Gates</td>
</tr>
<tr>
<th rowspan="2">Telephone:</th>
<td>555 77 854</td>
</tr>
<tr>
<td>555 77 855</td>
</tr>
</table>
Try it Yourself
Example
<table style="width:100%">
<caption>Monthly savings</caption>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$50</td>
</tr>
</table>
Try it Yourself
The <caption> tag must be inserted immediately after the <table> tag.
Example
<table id="t01">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Points</th>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
Try it Yourself
Try it Yourself
HTML Lists
Previous
Next Chapter
The
The
The
The
first item
second item
third item
fourth item
The
The
The
The
first item
second item
third item
fourth item
Unordered List:
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Try it Yourself
Description
list-style-type:disc
list-style-type:circle
list-style-type:square
list-style-type:none
Disc:
<ul style="list-style-type:disc">
<li>Coffee</li>
<li>Tea
<li>Milk</li>
</ul>
Try it Yourself
Circle:
<ul style="list-style-type:circle">
<li>Coffee</li>
<li>Tea
<li>Milk</li>
</ul>
Try it Yourself
Square:
<ul style="list-style-type:square">
<li>Coffee</li>
<li>Tea
<li>Milk</li>
</ul>
Try it Yourself
None:
<ul style="list-style-type:none">
<li>Coffee</li>
<li>Tea
<li>Milk</li>
</ul>
Try it Yourself
But in HTML5, the type attribute is not valid in unordered lists, only in ordered list.
Ordered List:
<ol>
<li>Coffee</li>
<li>Milk</li>
</ol>
Try it Yourself
Description
type="1"
type="A"
type="a"
type="I"
type="i"
Numbers:
<ol type="1">
<li>Coffee</li>
<li>Tea
<li>Milk</li>
</ol>
Try it Yourself
Upper Case:
<ol type="A">
<li>Coffee</li>
<li>Tea
<li>Milk</li>
</ol>
Try it Yourself
Lower Case:
<ol type="a">
<li>Coffee</li>
<li>Tea
<li>Milk</li>
</ol>
Try it Yourself
Try it Yourself
Try it Yourself
Description List:
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
Try it Yourself
Nested Lists:
<ul>
<li>Coffee</li>
<li>Tea
<ul>
<li>Black tea</li>
<li>Green tea</li>
</ul>
</li>
<li>Milk</li>
</ul>
Try it Yourself
List items can contain new list, and other HTML elements, like images and links, etc.
Horizontal Lists
HTML lists can be styled in many different ways with CSS.
One popular way, is to style a list to display horizontally:
Horizontal List:
<!DOCTYPE html>
<html>
<head>
<style>
ul#menu li {
display:inline;
}
</style>
</head>
<body>
<h2>Horizontal List</h2>
<ul id="menu">
<li>Apples</li>
<li>Bananas</li>
<li>Lemons</li>
<li>Oranges</li>
</ul>
</body>
</html>
Try it Yourself
With a little extra style, you can make it look like a menu:
Tables
Lists
Blocks
Classes
New Style:
ul#menu {
padding: 0;
}
ul#menu li {
display: inline;
}
ul#menu li a {
background-color: black;
color: white;
padding: 10px 20px;
text-decoration: none;
border-radius: 4px 4px 0 0;
}
ul#menu li a:hover {
background-color: orange;
}
Try it Yourself