Category: 

What Is an HTML Margin?

Article Details
  • Written By: Mary McMahon
  • Edited By: Shereen Skola
  • Last Modified Date: 01 November 2016
  • Copyright Protected:
    2003-2016
    Conjecture Corporation
  • Print this Article
Free Widgets for your Site/Blog
President Richard Nixon had an entire speech prepared in case the Apollo 11 astronauts became stranded on the Moon.  more...

December 8 ,  1965 :  Pope Paul VI promulgated Vatican II into ecumenical law.  more...

A hypertext markup language (HTML) margin is a property that determines the spacing outside elements. It can be used in context with padding, the space inside elements, to organize objects visually. Margins may be necessary for ease of reading as well as aesthetic purposes. When elements are crammed closely together, it can give a website a busy look that may be off-putting to users. Correct spacing with an HTML margin creates a more balanced, even appearance that remains visually interesting, but not overwhelming.

When a developer sets the HTML margin, it can take up to four values. If a single value is given, the browser will assume the margins around the object should be the same on all sides. For two values, it will use the first for the top and bottom, and the second for the left and right. Three values outline the top margin, the measurements at the sides, and the bottom. In cases where all four are defined, the browser will set the top, left, right, and bottom as specified.

Ad

Each HTML margin provides some visual space around the outside of an element. In a classic example, a web designer might have a navigation bar at the top of a page. Without margins, the next element, like a box with content, would butt immediately up against the navigation bar. This would not look very pleasant, and also might make the site difficult for users to use. An HTML margin could provide space around the content, creating clearance between the menu and the content to separate them visually.

Designers can set an HTML margin as a percentage, or in a value like em or pixels. The best option can depend on the designer’s preferences and the overall look and feel of the site. It is important to use consistent measurements in the design. If margins are given in percentages, for example, so should padding, to avoid conflicts.

Another consideration can be changes to screen size or display, which may occur on mobile devices or computers where users magnify the content for readability. If the design is not flexible, content may spill out of containers, run off the page, or fail to magnify properly. This can make the site hard to read, and in some cases may break the content so users cannot access it at all. In testing, designers may explore several different browsers and could experiment with magnification and shrinkage to see what happens to the display.

Ad

You might also Like

Recommended

Discuss this Article

Post your comments

Post Anonymously

Login

username
password
forgot password?

Register

username
password
confirm
email