HTML(5) Tutorial - 161.246.38.75

Transcription

9/2/2015HTML TutorialPrint PageHTML(5) Tutorial« W3Schools Home (/default.asp)Next Chapter » (html intro.asp)With HTML you can create your own Web site.This tutorial teaches you everything about HTML.HTML is easy to learn You will enjoy it.Examples in Every ChapterThis HTML tutorial contains hundreds of HTML examples.With our online HTML editor, you can edit the HTML, and click on a button to view the result.Example !DOCTYPE html html head title Page Title /title /head body h1 This is a Heading /h1 p This is a paragraph. /p /body /html Try it Yourself » (tryit.asp?filename tryhtml default)Click on the "Try it Yourself" button to see how it works.Start learning HTML now! (html intro.asp)HTML ExamplesAt the end of the HTML tutorial, you can find more than 200 1/3

9/2/2015HTML TutorialWith our online editor, you can edit and test each example yourself.Go to HTML Examples! (html examples.asp)HTML Quiz TestTest your HTML skills at W3Schools!Start HTML Quiz! (html quiz.asp)HTML ReferencesAt W3Schools you will find complete references about tags, attributes, events, color names, entities,character sets, URL encoding, language codes, HTTP messages, and more.HTML Tag Reference (/tags/default.asp)HTML Exam Get Your Diploma!(/cert/default.asp)W3Schools' OnlineCertificationThe perfect solution for professionals who need to balancework, family, and career building.More than 10 000 certificates already issued!Get Your Certificate » (/cert/default.asp)The HTML Certificate (/cert/default.asp) documents your knowledge of HTML.The HTML5 Certificate (/cert/default.asp) documents your knowledge of advanced HTML5.The CSS Certificate (/cert/default.asp) documents your knowledge of advanced CSS.The JavaScript Certificate (/cert/default.asp) documents your knowledge of JavaScript and HTMLDOM.The jQuery Certificate (/cert/default.asp) documents your knowledge of jQuery.The PHP Certificate (/cert/default.asp) documents your knowledge of PHP and SQL (MySQL).The XML Certificate (/cert/default.asp) documents your knowledge of XML, XML DOM and XSLT.« W3Schools Home t.aspNext Chapter » (html intro.asp)2/3

9/2/2015HTML TutorialCopyright 1999 2015 (/about/about copyright.asp) by Refsnes Data. All Rights 3/3

9/2/2015Introduction to HTMLPrint PageHTML Introduction« Previous (default.asp)Next Chapter » (html editors.asp)What is HTML?HTML is a markup language for describing web documents (web pages).HTML stands for Hyper Text Markup LanguageA markup language is a set of markup tagsHTML documents are described by HTML tagsEach HTML tag describes different document contentHTML ExampleA small HTML document: !DOCTYPE html html head title Page Title /title /head body h1 My First Heading /h1 p My first paragraph. /p /body /html Try it Yourself » (tryit.asp?filename tryhtml intro)Example ExplainedTheTheTheTheTheTheTheDOCTYPE declaration defines the document type to be HTMLtext between html and /html describes an HTML documenttext between head and /head provides information about the documenttext between title and /title provides a title for the documenttext between body and /body describes the visible page contenttext between h1 and /h1 describes a headingtext between p and /p describes a paragraphhttp://www.w3schools.com/html/html intro.asp1/4

9/2/2015Introduction to HTMLUsing this description, a web browser can display a document with a heading and a paragraph.HTML TagsHTML tags are keywords (tag names) surrounded by angle brackets: tagname content /tagname HTML tags normally come in pairs like p and /p The first tag in a pair is the start tag, the second tag is the end tagThe end tag is written like the start tag, but with a slash before the tag nameThe start tag is often called the opening tag. The end tag is often called the closingtag.Web BrowsersThe purpose of a web browser (Chrome, IE, Firefox, Safari) is to read HTML documents and displaythem.The browser does not display the HTML tags, but uses them to determine how to display thedocument:HTML Page StructureBelow is a visualization of an HTML page structure:http://www.w3schools.com/html/html intro.asp2/4

9/2/2015Introduction to HTML html head title Page title /title /head body h1 This is a heading /h1 p This is a paragraph. /p p This is another paragraph. /p /body /html Only the body area (the white area) is displayed by the browser.The !DOCTYPE DeclarationThe !DOCTYPE declaration helps the browser to display a web page correctly.There are different document types on the web.To display a document correctly, the browser must know both type and version.The doctype declaration is not case sensitive. All cases are acceptable: !DOCTYPE html !DOCTYPE HTML !doctype html !Doctype Html Common Declarationshttp://www.w3schools.com/html/html intro.asp3/4

9/2/2015Introduction to HTMLHTML5 !DOCTYPE html HTML 4.01 !DOCTYPE HTML PUBLIC "‐//W3C//DTD HTML 4.01 .dtd" XHTML 1.0 !DOCTYPE html PUBLIC "‐//W3C//DTD XHTML 1.0 xhtml1‐transitional.dtd" All tutorials and examples at W3Schools use HTML5.HTML VersionsSince the early days of the web, there have been many versions of HTML:VersionYearHTML1991HTML 2.01995HTML 3.21997HTML 4.011999XHTML2000HTML52014« Previous (default.asp)Next Chapter » (html editors.asp)Copyright 1999 2015 (/about/about copyright.asp) by Refsnes Data. All Rights Reserved.http://www.w3schools.com/html/html intro.asp4/4

9/2/2015HTML EditorsPrint PageHTML Editors« Previous (html intro.asp)Next Chapter » (html basic.asp)Write HTML Using Notepad or TextEditHTML can be edited by using professional HTML editors like:Microsoft WebMatrixSublime TextHowever, 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.Step 1: Open NotepadTo open Notepad in Windows 7 or earlier:Click Start (bottom left on your screen). Click All Programs. Click Accessories. Click Notepad.To open Notepad in Windows 8 or later:Open the Start Screen (the window symbol at the bottom left on your screen). Type Notepad.Step 2: Write Some HTMLWrite or copy some HTML into Notepad. !DOCTYPE html html body h1 My First Heading /h1 p My first paragraph. /p /body /html http://www.w3schools.com/html/html editors.asp1/3

9/2/2015HTML EditorsStep 3: Save the HTML PageSave the file on your computer.Select File Save as in the Notepad menu.Name the file "index.html" or any other name ending with html or htm.UTF 8 is the preferred encoding for HTML files.ANSI encoding covers US and Western European characters only.You can use either .htm or .html as file extension. There is no difference, it is up toyou.Step 4: View HTML Page in Your BrowserOpen the saved HTML file in your favorite browser. The result will look much like this:http://www.w3schools.com/html/html editors.asp2/3

9/2/2015HTML EditorsTo open a file in a browser, double click on the file, or right click, and choose openwith.« Previous (html intro.asp)Next Chapter » (html basic.asp)Copyright 1999 2015 (/about/about copyright.asp) by Refsnes Data. All Rights Reserved.http://www.w3schools.com/html/html editors.asp3/3

9/2/2015HTML BasicPrint PageHTML Basic Examples« Previous (html editors.asp)Next Chapter » (html elements.asp)Don't worry if these examples use tags you have not learned.You will learn about them in the next chapters.HTML DocumentsAll 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 Try it Yourself » (tryit.asp?filename tryhtml basic document)HTML HeadingsHTML 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 Try it Yourself » (tryit.asp?filename tryhtml basic headings)http://www.w3schools.com/html/html basic.asp1/3

9/2/2015HTML BasicHTML ParagraphsHTML paragraphs are defined with the p tag:Example p This is a paragraph. /p p This is another paragraph. /p Try it Yourself » (tryit.asp?filename tryhtml basic paragraphs)HTML LinksHTML links are defined with the a tag:Example a href "http://www.w3schools.com" This is a link /a Try it Yourself » (tryit.asp?filename tryhtml basic link)The link's destination is specified in the href attribute.Attributes are used to provide additional information about HTML elements.HTML ImagesHTML 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" Try it Yourself » (tryit.asp?filename tryhtml basic img)You will learn more about attributes in a later chapter.http://www.w3schools.com/html/html basic.asp2/3

9/2/2015« Previous (html editors.asp)HTML BasicNext Chapter » (html elements.asp)Copyright 1999 2015 (/about/about copyright.asp) by Refsnes Data. All Rights Reserved.http://www.w3schools.com/html/html basic.asp3/3

9/2/2015HTML ElementsPrint PageHTML Elements« Previous (html basic.asp)Next Chapter » (html attributes.asp)HTML documents are made up by HTML elements.HTML ElementsHTML 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: p My first HTML paragraph. /p Start tagElement contentEnd tag h1 My First Heading /h1 p My first paragraph. /p br Some HTML elements do not have an end tag.Nested HTML ElementsHTML elements can be nested (elements can contain elements).All HTML documents consist of nested HTML elements.This example contains 4 HTML elements:Example !DOCTYPE html html body http://www.w3schools.com/html/html elements.asp1/4

9/2/2015HTML Elements h1 My First Heading /h1 p My first paragraph. /p /body /html Try it yourself » (tryit.asp?filename tryhtml elements)HTML Example ExplainedThe html element defines the whole document.It has a start tag html and an end tag /html .The element content is another HTML element (the body element). html body h1 My First Heading /h1 p My first paragraph. /p /body /html The body element defines the document body.It has a start tag body and an end tag /body .The element content is two other HTML elements ( h1 and p ). body h1 My First Heading /h1 p My first paragraph. /p /body The h1 element defines a heading.It has a start tag h1 and an end tag /h1 .The element content is: My First Heading. h1 My First Heading /h1 The p element defines a paragraph.It has a start tag p and an end tag /p .http://www.w3schools.com/html/html elements.asp2/4

9/2/2015HTML ElementsThe element content is: My first paragraph. p My first paragraph. /p Don't Forget the End TagSome HTML elements will display correctly, even if you forget the end tag:Example html body p This is a paragraph p This is a paragraph /body /html Try it yourself » (tryit.asp?filename tryhtml no endtag)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.Empty HTML ElementsHTML elements with no content are called empty elements. br is an empty element without a closing tag (the br tag defines a line break).Empty elements can be "closed" in the opening tag like this: br / .HTML5 does not require empty elements to be closed. But if you want stricter validation, or you needto make your document readable by XML parsers, you should close all HTML elements.HTML Tip: Use Lowercase TagsHTML tags are not case sensitive: P means the same as p .The HTML5 standard does not require lowercase tags, but W3C recommends lowercase in HTML4,and demands lowercase for stricter document types like XHTML.At W3Schools we always use lowercase tags.http://www.w3schools.com/html/html elements.asp3/4

9/2/2015« Previous (html basic.asp)HTML ElementsNext Chapter » (html attributes.asp)Copyright 1999 2015 (/about/about copyright.asp) by Refsnes Data. All Rights Reserved.http://www.w3schools.com/html/html elements.asp4/4

9/2/2015HTML AttributesPrint PageHTML Attributes« Previous (html elements.asp)Next Chapter » (html headings.asp)Attributes provide additional information about HTML elements.HTML AttributesHTML elements can have attributesAttributes provide additional information about an elementAttributes are always specified in the start tagAttributes come in name/value pairs like: name "value"The lang AttributeThe document language can be declared in the html tag.The language is declared in the lang attribute.Declaring a language is important for accessibility applications (screen readers) and search engines: !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).The title AttributeHTML paragraphs are defined with the p tag.In this example, the p element has a title attribute. The value of the attribute is tml/html attributes.asp1/5

9/2/2015HTML Attributes p title "About W3Schools" W3Schools is a web developer's site.It provides tutorials and references coveringmany aspects of web programming,including HTML, CSS, JavaScript, XML, SQL, PHP, ASP, etc. /p Try it Yourself » (tryit.asp?filename tryhtml attributes title)When you move the mouse over the element, the title will be displayed as a tooltip.The href AttributeHTML links are defined with the a tag. The link address is specified in the href attribute:Example a href "http://www.w3schools.com" This is a link /a Try it Yourself » (tryit.asp?filename tryhtml attributes link)You will learn more about links and the a tag later in this tutorial.Size AttributesHTML images are defined with the img tag.The filename of the source (src), and the size of the image (width and height) are all provided asattributes:Example img src "w3schools.jpg" width "104" height "142" Try it Yourself » (tryit.asp?filename tryhtml attributes img)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.The alt Attributehttp://www.w3schools.com/html/html attributes.asp2/5

9/2/2015HTML AttributesThe alt attribute specifies an alternative text to be used, when an HTML element cannot bedisplayed.The value of the attribute can be read by "screen readers". This way, someone "listening" to thewebpage, i.e. a blind person, can "hear" the element.Example img src "w3schools.jpg" alt "W3Schools.com" width "104" height "142" Try it Yourself » (tryit.asp?filename tryhtml attributes alt)We Suggest: Always Use Lowercase AttributesThe HTML5 standard does not require lower case attribute names.The title attribute can be written with upper or lower case like Title and/or TITLE.W3C recommends lowercase in HTML4, and demands lowercase for stricter document types likeXHTML.Lower case is the most common. Lower case is easier to type.At W3Schools we always use lower case attribute names.We Suggest: Always Quote Attribute ValuesThe HTML5 standard does not require quotes around attribute values.The href attribute, demonstrated above, can be written as:Example a href http://www.w3schools.com Try it Yourself » (tryit.asp?filename tryhtml attributes noquotes)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 Try it Yourself » (tryit.asp?filename tryhtml attributes error)http://www.w3schools.com/html/html attributes.asp3/5

9/2/2015HTML AttributesUsing quotes are the most common. Omitting quotes can produce errors.At W3Schools we always use quotes around attribute values.Single or Double Quotes?Double style quotes are the most common in HTML, but single style can also be used.In some situations, when the attribute value itself contains double quotes, it is necessary to use singlequotes: p title 'John "ShotGun" Nelson' Or vice versa: p title "John 'ShotGun' Nelson" Chapter SummaryAll HTML elements can have attributesThe HTML title attribute provides additional "tool tip" informationThe HTML href attribute provides address information for linksThe HTML width and height attributes provide size information for imagesThe HTML alt attribute provides text for screen readersAt W3Schools we always use lowercase HTML attribute namesAt W3Schools we always quote attributes with double quotesTest Yourself with Exercises!Exercise 1 » (exercise.asp?filename exercise attributes1)Exercise 2 » (exercise.asp?filename exercise attributes2)Exercise 3 » (exercise.asp?filename exercise attributes3)Exercise 4 » (exercise.asp?filename exercise attributes4)Exercise 5 » (exercise.asp?filename exercise attributes5)http://www.w3schools.com/html/html attributes.asp4/5

9/2/2015HTML AttributesHTML AttributesBelow is an alphabetical list of some attributes often used in HTML:AttributeDescriptionaltSpecifies an alternative text for an imagedisabledSpecifies that an input element should be disabledhrefSpecifies the URL (web address) for a linkidSpecifies a unique id for an elementsrcSpecifies the URL (web address) for an imagestyleSpecifies an inline CSS style for an elementtitleSpecifies extra information about an element (displayed as a tool tip)valueSpecifies the value (text content) for an input element.A complete list of all attributes for each HTML element, is listed in our: HTML Tag Reference(/tags/default.asp).« Previous (html elements.asp)Next Chapter » (html headings.asp)Copyright 1999 2015 (/about/about copyright.asp) by Refsnes Data. All Rights Reserved.http://www.w3schools.com/html/html attributes.asp5/5

9/2/2015Exercise v1.3Exercise:Add a tooltip to the paragraph below with the text "About W3Schools".HintEdit This Code:See Result » !DOCTYPE html html body Result:Show AnswerW3Schools is a web developer's site. p W3Schools is a web developer's site. /p /body /html Exercise e.asp?filename exercise attributes11/1

9/2/2015Exercise v1.3Exercise:Change the size of the image to 250 pixels wide and 400 pixels tall.HintEdit This Code:See Result »Result:Show Answer !DOCTYPE html html body img src "w3schools.jpg" width "104"height "142" /body /html Exercise e.asp?filename exercise attributes21/1

9/2/2015Exercise v1.3Exercise:Transform the text below into a link that goes to "www.w3schools.com".HintEdit This Code:See Result » !DOCTYPE html html body Result:Show AnswerThis is a linkThis is a link /body /html Exercise e.asp?filename exercise attributes31/1

9/2/2015Exercise v1.3Exercise:Change the destination of the link below to "www.wwf.org.uk".HintEdit This Code:See Result » !DOCTYPE html html body Result:Show AnswerThis is a link a href "http://www.w3schools.com" This isa link /a /body /html Exercise e.asp?filename exercise attributes41/1

9/2/2015Exercise v1.3Exercise:The image below is unavailable on purpose. Specify an alternate text of "w3schools.com" tobe used,so it can be read by "screen readers".HintEdit This Code:See Result »Result:Show Answer !DOCTYPE html html body img src "w3schooooools.jpg" width "135"height "50" /body /html Exercise e.asp?filename exercise attributes51/1

9/2/2015HTML HeadingsPrint PageHTML Headings« Previous (html attributes.asp)Next Chapter » (html paragraphs.asp)Headings are important in HTML documents.HTML HeadingsHeadings 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 Try it Yourself » (tryit.asp?filename tryhtml headings)Note: Browsers automatically add some empty space (a margin) before and after each heading.Headings Are ImportantUse HTML headings for headings only. Don't use headings to make text BIG or bold.Search engines use your headings to index the structure and content of your web pages.Users skim your pages by its headings. It is important to use headings to show the documentstructure.h1 headings should be main headings, followed by h2 headings, then the less important h3, and soon.HTML Horizontal RulesThe hr tag creates a horizontal line in an HTML page.The hr element can be used to separate content:Examplehttp://www.w3schools.com/html/html headings.asp1/4

9/2/2015HTML Headings p This is a paragraph. /p hr p This is a paragraph. /p hr p This is a paragraph. /p Try it Yourself » (tryit.asp?filename tryhtml headings hr)The HTML head ElementThe HTML head element has nothing to do with HTML headings.The HTML head element contains meta data. Meta data are not displayed.The HTML head element is placed between the html tag and the body tag:Example !DOCTYPE html html head title My First HTML /title meta charset "UTF‐8" /head body .Try it Yourself » (tryit.asp?filename tryhtml headings head)Meta data means data about data. HTML meta data is data about the HTMLdocument.The HTML title ElementThe HTML title element is meta data. It defines the HTML document's title.The title will not be displayed in the document, but might be displayed in the browser tab.The HTML meta ElementThe HTML meta element is also meta data.http://www.w3schools.com/html/html headings.asp2/4

9/2/2015HTML HeadingsIt can be used to define the character set, and other information about the HTML document.More Meta ElementsIn the chapter about HTML styles you discover more meta elements:The HTML style element is used to define internal CSS style sheets.The HTML link element is used to define external CSS style sheets.HTML Tip How to View HTML SourceHave you ever seen a Web page and wondered "Hey! How did they do that?"To find out, right click in the page and select "View Page Source" (in Chrome) or "View Source" (inIE), or similar in another browser. This will open a window containing the HTML code of the page.Test Yourself with Exercises!Exercise 1 » (exercise.asp?filename exercise headings1)Exercise 2 » (exercise.asp?filename exercise headings2)Exercise 3 » (exercise.asp?filename exercise headings3)Exercise 4 » (exercise.asp?filename exercise headings4)HTML Tag ReferenceW3Schools' tag reference contains additional information about these tags and their attributes.You will learn more about HTML tags and attributes in the next chapters of this tutorial.TagDescription html (/tags/tag html.asp)Defines an HTML document body (/tags/tag body.asp)Defines the document's body head (/tags/tag head.asp)Defines the document's head element h1 to h6 (/tags/tag hn.asp)Defines HTML headings hr (/tags/tag hr.asp)Defines a horizontal linehttp://www.w3schools.com/html/html headings.asp3/4

9/2/2015« Previous (html attributes.asp)HTML HeadingsNext Chapter » (html paragraphs.asp)Copyright 1999 2015 (/about/about copyright.asp) by Refsnes Data. All Rights Reserved.http://www.w3schools.com/html/html headings.asp4/4

9/2/2015Exercise v1.3Exercise:Add a horizontal rule between the heading and the paragraph.HintEdit This Code:See Result » !DOCTYPE html html body h1 London /h1 p London is the capital city of England.It is the most populous city in the UnitedKingdom, with a metropolitan area of over13 million inhabitants. /p Result:Show AnswerLondonLondon is the capital city of England. It is themost populous city in the United Kingdom, witha metropolitan area of over 13 millioninhabitants. /body /html Exercise e.asp?filename exercise headings21/1

9/2/2015Exercise v1.3Exercise:Add six headings to the document with the text "Hello".Start with the most important heading and end with the least important heading.HintEdit This Code:See Result »Result:Show Answer !DOCTYPE html html body /body /html Exercise e.asp?filename exercise headings31/1

9/2/2015Exercise v1.3Exercise:Mark up the following text with appropriate tags:"Universal Studios" is the most important content."Jurassic Park" is the next most important content."About" is of lesser importance than Jurassic Park.The last sentence is just a paragraph.HintEdit This Code:See Result » !DOCTYPE html html body Universal Studios PresentsResult:Show AnswerUniversal Studios Presents Jurassic Park AboutOn the Island of Isla Nublar, a new park has beenbuilt: Jurassic Park is a theme park of cloneddinosaurs!!Jurassic ParkAboutOn the Island of Isla Nublar, a new parkhas been built: Jurassic Park is a themepark of cloned dinosaurs!! /body /html Exercise e.asp?filename exercise headings41/1

9/2/2015HTML ParagraphsPrint PageHTML Paragraphs« Previous (html headings.asp)Next Chapter » (html styles.asp)HTML documents are divided into paragraphs.HTML ParagraphsThe HTML p element defines a paragraph.Example p This is a paragraph /p p This is another paragraph /p Try it Yourself » (tryit.asp?filename tryhtml paragraphs1)Browsers automatically add an empty line before and after a paragraph.HTML DisplayYou 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 paragraphcontains a lot of linesin the source code,but the browserignores it. /p p http://www.w3schools.com/html/html paragraphs.asp1/4

9/2/2015HTML ParagraphsThis paragraphcontainsa lot of spacesin the sourcecode,but thebrowserignores it. /p Try it Yourself » (tryit.asp?filename tryhtml paragraphs2)Don't Forget the End TagMost browsers will display HTML correctly even if you forget the end tag:Example p This is a paragraph p This is another paragraphTry it Yourself » (tryit.asp?filename tryhtml paragraphs0)The example above will work in most browsers, but do not 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.HTML Line BreaksThe HTML br element defines a line break.Use br if you want a line break (a new line) without starting a new paragraph:Example p This is br a para br graph with line breaks /p Try it Yourself » (tryit.asp?filename tryhtml paragraphs)The br element is an empty HTML element. It has no end tag.The Poem Problemhttp://www.w3schools.com/html/html paragraphs.asp2/4

9/2/2015HTML ParagraphsExample p This poem will display as one line: /p p 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. /p Try it Yourself » (tryit.asp?filename tryhtml poem)The HTML pre ElementThe HTML pre element defines preformatted text.The text inside a pre element is displayed in a fixed width font (usually Courier), and it preservesboth spaces and line breaks:Example 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 Try it Yourself » (tryit.asp?filename tryhtml pre)Test Yourself with Exercises!Exercise 1 » (exercise.asp?filename exercise paragraphs)Exercise 2 » (exercise.asp?filename exercise paragraphs1)Exercise 3 » (exercise.asp?filename exercise paragraphs2)Exercise 4 » (exercise.asp?filename exercise paragraphs3)http://www.w3schools.com/html/html paragraphs.asp3/4

9/2/2015HTML ParagraphsHTML Tag ReferenceW3Schools' tag reference contains additional information about HTML elements and their attributes.TagDescription p (/tags/tag p.asp)Defines a paragraph br (/tags/tag br.asp)Inserts a single line break pre (/tags/tag pre.asp)Defines pre formatted text« Previous (html headings.asp)Next Chapter » (html styles.asp)Copyright 1999 2015 (/about/about copyright.asp) by Refsnes Data. All Rights Reserved.http://www.w3schools.com/html/html paragraphs.asp4/4

9/2/2015Exercise v1.3Exercise:Add a paragraph to this document with the text "Hello World!".HintEdit This Code:See Result »Result:Show Answer !DOCTYPE html html body /body /html Exercise e.asp?filename exercise paragraphs1/1

9/2/2015Exercise v1.3Exercise:Fix the display of the poem below. Display the poem over 4 lines.HintEdit This Code:See Result » !DOCTYPE html html body p My BonnieMy BonnieMy BonnieOh, bring /p liesliesliesbackResult:Show AnswerMy Bonnie lies over the ocean. My Bonnie liesover the sea. My Bonnie lies over the ocean. Oh,bring back my Bonnie to me.over the ocean.over the sea.over the ocean.my Bonnie to me. /body /html Exercise e.asp?filename exercise paragraphs21/1

Print PageHTML Styles« Previous (html paragraphs.asp)Next Chapter » (html formatting.asp)I am RedI am BlueTry it Yourself » (tryit.asp?filename tryhtml styles intro)HTML StylingEvery

« W3Schools Home (/default.asp) Next Chapter » (html_intro.asp) Print Page HTML(5) Tutorial With HTML you can create your own Web site. This tutorial teaches you everything about HTML. HTML is easy to learn You will enjoy it. Examples in Every Chapter This HTML