HTML text Formatting
HTML Text Formatting
HTML defines a lot of elements for formatting output, like bold or italic text.
Below are a lot of examples that you can try out yourself:
Examples
Text formattingThis example demonstrates how you can format text in an HTML document.
Preformatted textThis example demonstrates how you can control the line breaks and spaces with the pre tag.
"Computer output" tagsThis example demonstrates how different "computer output" tags will be displayed.
AddressThis example demonstrates how to write an address in an HTML document.
Abbreviations and acronymsThis example demonstrates how to handle an abbreviation or an acronym.
Text directionThis example demonstrates how to change the text direction.
QuotationsThis example demonstrates how to handle long and short quotations.
Deleted and inserted textThis example demonstrates how to mark a text that is deleted or inserted to a document.
How to View HTML Source
Have you ever seen a Web page and wondered "Hey! How did they do that?"
To find out, click the VIEW option in your browser's toolbar and select SOURCE or PAGE SOURCE. This will open a window that shows you the HTML code of the page.
Text Formatting Tags
Tag
Description
Defines bold text
Defines big text
Defines emphasized text
Defines italic text
Defines small text
Defines strong text
Defines subscripted text
Defines superscripted text
Defines inserted text
Defines deleted text
Deprecated. Use instead
Deprecated. Use instead
Deprecated. Use styles instead
"Computer Output" Tags
Tag
Description
Defines computer code text
Defines keyboard text
Defines sample computer code
Defines teletype text
Defines a variable
Defines preformatted text
Deprecated. Use instead
Deprecated. Use instead
Deprecated. Use instead
Citations, Quotations, and Definition Tags
Tag
Description
Defines an abbreviation
Defines an acronym
Defines an address element
Defines the text direction
Defines a long quotation
Defines a short quotation
Defines a citation
Defines a definition term
HTML Character Entities
Some characters like the < character, have a special meaning in HTML, and therefore cannot be used in the text.
To display a less than sign (<) in HTML, we have to use a character entity.
Character Entities
Some characters have a special meaning in HTML, like the less than sign (<) that defines the start of an HTML tag. If we want the browser to actually display these characters we must insert character entities in the HTML source.
A character entity has three parts: an ampersand (&), an entity name or a # and an entity number, and finally a semicolon (;).
To display a less than sign in an HTML document we must write: < or <
The advantage of using a name instead of a number is that a name is easier to remember. The disadvantage is that not all browsers support the newest entity names, while the support for entity numbers is very good in almost all browsers.
Note that the entities are case sensitive.
This example lets you experiment with character entities: Character Entities
Non-breaking Space
The most common character entity in HTML is the non-breaking space.
Normally HTML will truncate spaces in your text. If you write 10 spaces in your text HTML will remove 9 of them. To add spaces to your text, use the character entity.
The Most Common Character Entities:
Result
Description
Entity Name
Entity Number
non-breaking space
<
less than
<
<
>
greater than
>
>
&
ampersand
&
&
"
quotation mark
"
"
'
apostrophe
' (does not work in IE)
'
Some Other Commonly Used Character Entities:
Result
Description
Entity Name
Entity Number
¢
cent
¢
¢
£
pound
£
£
¥
yen
¥
¥
€
euro
€
€
§
section
§
§
©
copyright
©
©
®
registered trademark
®
®
×
multiplication
×
×
÷
division
÷
÷
To see a full list of HTML character entities go to our HTML Entities Reference.
HTML Links
HTML uses a hyperlink to link to another document on the Web.
Examples
Create hyperlinksThis example demonstrates how to create links in an HTML document.
An image as a linkThis example demonstrates how to use an image as a link.
(You can find more examples at the bottom of this page)
The Anchor Tag and the Href Attribute
HTML uses the (anchor) tag to create a link to another document.
An anchor can point to any resource on the Web: an HTML page, an image, a sound file, a movie, etc.
The syntax of creating an anchor:
Text to be displayed
The tag is used to create an anchor to link from, the href attribute is used to address the document to link to, and the words between the open and close of the anchor tag will be displayed as a hyperlink.
This anchor defines a link to W3Schools:
Visit W3Schools!
The line above will look like this in a browser:
Visit W3Schools!
The Target Attribute
With the target attribute, you can define where the linked document will be opened.
The line below will open the document in a new browser window:
Visit W3Schools!
The Anchor Tag and the Name Attribute
The name attribute is used to create a named anchor. When using named anchors we can create links that can jump directly into a specific section on a page, instead of letting the user scroll around to find what he/she is looking for.
Below is the syntax of a named anchor:
Text to be displayed
The name attribute is used to create a named anchor. The name of the anchor can be any text you care to use.
The line below defines a named anchor:
Useful Tips Section
You should notice that a named anchor is not displayed in a special way.
To link directly to the "tips" section, add a # sign and the name of the anchor to the end of a URL, like this:
Jump to the Useful Tips Section
A hyperlink to the Useful Tips Section from WITHIN the file "html_links.asp" will look like this:
Jump to the Useful Tips Section
Basic Notes - Useful Tips
Always add a trailing slash to subfolder references. If you link like this: href="http://www.w3schools.com/html", you will generate two HTTP requests to the server, because the server will add a slash to the address and create a new request like this: href="http://www.w3schools.com/html/"
Named anchors are often used to create "table of contents" at the beginning of a large document. Each chapter within the document is given a named anchor, and links to each of these anchors are put at the top of the document.
If a browser cannot find a named anchor that has been specified, it goes to the top of the document. No error occurs.
More Examples
Open a link in a new browser windowThis example demonstrates how to link to another page by opening a new window, so that the visitor does not have to leave your Web site.
Link to a location on the same pageThis example demonstrates how to use a link to jump to another part of a document.
Break out of a frameThis example demonstrates how to break out of a frame, if your site is locked in a frame.
Create a mailto linkThis example demonstrates how to link to a mail message (will only work if you have mail installed).
Create a mailto link 2This example demonstrates a more complicated mailto link.
Link Tags
Tag
Description
Defines an anchor
5:10 AM
|
|
This entry was posted on 5:10 AM
You can follow any responses to this entry through
the RSS 2.0 feed.
You can leave a response,
or trackback from your own site.
0 comments:
Post a Comment