Web Design Stuff
HTML Tutorials    CSS Tutorials    Web Hosting   Resources
Create a Web Page 101
Making Web Pages Intro What is a Web Page? Why Make a Web Page? The History of HTML Learn HTML or XHTML?
Basic HTML
Basic HTML Tutorials Basic HTML Necessities How to Make a Web Page How to Edit a Web Page The Basics of HTML Tags Basic HTML Page Structure HTML Attributes
HTML Font Codes
HTML Font Codes Intro HTML Font Color Codes HTML Font Size Codes HTML Font Style Codes HTML Bold/Italic Codes Combining Font Codes
Formatting Text
Formatting Text Intro Making Paragraphs Miscellaneous Formatting Headings & Subheadings Creating Hyperlinks
Using Graphics
Using Graphics on the Web Add Graphics to Your Pages Graphics and Accessibility How to Align Graphics Page Color & Background Graphics as Hyperlinks Horizontal Rules
Creating Tables
HTML Tables Tutorials HTML Table Fundamentals Background & Border Color Table Frames & Rules Table Width and Alignment Cells 1 -Space & Alignment Cells 2 -Row Column Span Cells 3 -Width & Height
Making Lists
HTML Lists Tutorials Bulleted Lists Numbered Lists Definition Lists
HTML Frames
HTML Frames Tutorials Using Frames for Layout Advanced Frame Layouts Putting Hyperlinks in Frames Frame Border Width Color, Margin and Control Problems with Frames SmartFrames: A Solution SSI: An Alternative to Frames
Web Page Forms
Making Feedback Forms A Simple Feedback Form Installing NMS FormMail Debugging Your Setup My Web Host is Out to Lunch User Input Components Text Fields Checkboxes & Radio Buttons Dropdown Menus Push Buttons Layout and Presentation
Basic CSS
Basic CSS Tutorials What is CSS? Why You Should Use CSS How to Use CSS Inline Styles Embedded Style Sheets External Style Sheets Class Selectors ID Selectors Combining Selectors
CSS Properties
CSS Properties Intro Font Styles Width, Height & Spacing Borders Backgrounds Position Float & Alignment Hyperlinks
All About Web Hosting
Hosting Your Own Website What is a Web Host? Your Website's Home Page Building a Website Offline About Free Web Hosting Best Free Web Hosting Commercial Web Hosting How to Get a Domain Name Ecommerce Web Hosting Web Hosting Terminology
Free Web Design Tools
Best Free Website Tools Best Free Text Editors Best Free Graphics Editors Free Website Analysis Tools
Setting Up HTML Kit
HTML Kit Introduction How to install HTML Kit Screenshot Breakdown Basic Configuration Overall Appearance Shortcuts and Startup Editing Window Customizing Toolbars Using the Favorites Tab Making a New Actions Bar Odds and Ends
Free Templates
Free Website Templates Two Column Fixed Width Three Column Liquid Layout Miscellaneous Templates Dynamic Menu Effects Two Column Experimental Terms of Use About These Templates
Website Templates Help
Getting Started Template Zip File Download How to Edit Your Template What to Edit in the HTML How to Add Your Logo Making a Website
Web Design Tips
Web Design Basics Tables vs. Tableless Using Tables for Layout Example Table Layouts World's Crappiest Web Page
Twitter Backgrounds
Twitter Backgrounds Intro Cool Twitter Backgrounds Cool Twitter Backgrounds 2 Plain Twitter Backgrounds Dark Twitter Backgrounds Best Twitter Backgrounds Cute Twitter Backgrounds Music Twitter Backgrounds Music Twitter Backgrounds 2 Twitter Backgrounds 101 TERMS OF USE
All About Web Browsers
What is a Web Browser? Mozilla Firefox Internet Explorer Opera How to Set Up Firefox Top 5 Firefox Extensions
 
Contact
Post Some Feedback Send Me An Email Iron Spider Blog About Iron Spider... Site Conventions
 
 
 

 

Horizontal Rules

 
 
<hr
size="pixels"
width="pixels or percentage"
align="left, center or right"
color="color definition"
noshade>
 
 
 
Height in pixels
Width in pixels or percentage
Horizontal alignment
Defines the color*
Draw as one solid color
HTML has a kind of built-in graphic that can be used to draw horizontal rules on your web page. This is accomplished with the hr element which is an empty element, i.e. it contains no content and only employs a start tag. Horizontal rules have a number of uses including acting as dividers to graphically separate your web page into sections or as underlining for headings.

Using the <hr> tag alone without any attributes or values will draw a horizontal rule at the default height (2 pixels), at the default width (100% of the available horizontal space) and —depending on the browser— with a simple two color groove effect.

The following example will illustrate:


Example 1 - SOURCE CODE
<hr>


Example 1 - RESULT



As with almost every other HTML element, there are a number of attributes and values that you can apply to the <hr> tag to alter the resulting effect. These are described in more detail below:

  • size="pixels" ~ Using the size attribute in the <hr> tag, you can specify the height of your horizontal rule in pixels. The number of pixels desired for the height is used as the value. Hence a size="5" attribute-value pair will draw a horizontal rule 5 pixels in height. The default height is 2 pixels.

  • width="pixels or percentage" ~ Using the width attribute, you can explicitly set the width of your horizontal rule. You may define either a fixed width in pixels or a relative width which will size your rule according to a percentage of the available space (typically the entire width of your web page). The default width is 100%.

    When defining a width in pixels, keep in mind the available space on your web page with respect to the screen resolution. For example, a rule using a width="900" attribute-value pair thus displaying it 900 pixels wide will outsize all screens using a resolution of 800 x 600. This will necessitate the insertion of horizontal scroll bars at the bottom of the user's web browser and may create an unattractive display.

    To avoid this predicament, you should either specify a fixed width that can fit within the screen resolution most visitors to your web page are likely to be using or you should define your horizontal rules in terms of a percentage of available space. When using percentages as values for the width attribute, web browsers will automatically resize your rule according to available screen space defined by the user's screen resolution. Thus a width="50%" attribute-value pair will display a rule at approximately 400 pixels in width on 800 x 600 screen resolution while displaying a rule approximately 512 pixels in width on 1024 x 768 screen resolution. Using percentages creates what is known as a 'liquid' display which accomodates itself to all screen resolutions.

  • align="left, center or right" ~ Assuming that your horizontal rule does not span or outsize the available space on your web page (see above), you can use the align attribute to position it to the left, in the center or to the right on your web page. Hence, using an align="left" attribute-value pair will align your horizontal rule flush to the left side of your web page (or the left side of the block element the rule is contained in). The default is center.

  • color="color definition" ~ Okay, I'm cheating again and *gasp* even teaching others to do so. Well what can I say. Guilty as charged. Ahem... Moving on... Although officially not listed in the HTML 4.01 Specification as an attribute-value pair to be used with the hr element, you can actually define the color of your horizontal rule using the color attribute and any legal color definition as the value. Hence, a color="purple" attribute-value pair will draw a purple horizontal rule. The default is gray.

    Be advised that this is only supported by Internet Explorer versions 5+ and Mozilla browsers. And, of course, any web pages containing horizontal rules using this attribute-value pair won't validate with the W3C specifications. For many people, however, just getting something to work in Internet Explorer is good enough since such a vast majority of web surfers use this browser. And to validate or not to validate? Well I could write a whole chapter on that. (Another time.) I try to validate my pages whenever possible. For all you sticklers out there, I plainly admit that the current page won't validate because I'm going to show you an example of using the color attribute in the hr element below.

    Be also advised that using the color attribute in the hr element will dispense with the default groove effect and will instead draw the rule as one solid color.

  • noshade ~ Using the noshade attribute (which stands alone and requires no accompanying value), you can explicitly dispense with the default two color groove effect most browsers use to draw horizontal rules. Simply place noshade in your <hr> tag to draw your rules as one solid gray color (unless otherwise defined by the color attribute), e.g. <hr noshade>.

Example 2 - SOURCE CODE
<hr width="50%" align="left">


Example 2 - RESULT



Example 3 - SOURCE CODE
<hr size="5" color="purple">


Example 3 - RESULT




Well well... So you've had a taste of formatting text on your web page and you know how to apply graphics and horizontal rules. Chances are that you now have a hankering to move on to more sophisticated HTML techniques such as laying out your text in tabular format.

So moving onward and upward, let's learn how to make HTML tables...





Best Free Stuff
for webmasters

Free Text Editors
Free Graphics Editors
Website Analysis Tools
Free Website Templates

See also:

Best Free Web Hosting

 

If you need a .COM web address, you can get one quick and easy at...

www.GoDaddy.com
<~ BACK TOP NEXT ~>
 
HTML Tutorials |  CSS Tutorials |  Web Hosting |  Domain Names |  Web Design Resources
Iron Spider © Copyright 2004-2011 Robert Darrell