Web Design Forums

Welcome! Please register or log in: Forgot your password? Why register?
You are here: Web Design Forums » Web Design Help » HTML and CSS Help » Simple Tag Question RSS

Simple Tag Question

This thread was started by MaryJo and has been viewed 305 times, and contains 6 replies, with the last reply made by nitin.
Post Reply
1
View MaryJo's reputation
Posted June 12 '09 at 05:12 PM
      Posts: 36
When does a tag need the closing tag <> </>
and when does it not? < >

My brain is fried from reading and being on the computer all day.

Thanks for your help

Advertisement Register for free to hide these ads and participate in discussions!

2
58 points at 100%
imagn, WDF Addict! Home page   Private message  
Posted June 12 '09 at 08:54 PM
      Posts: 156
There are only a few tags that don't need it and those would best be described as ones where content doesn't exist within them.
For example:
Line Breaks - <br />
Horizontal Rules - <hr />
In XHTML the traling "/>" acts as the closing tag.

3
View MaryJo's reputation
Posted June 12 '09 at 09:44 PM
      Posts: 36
Thanks imagn - That was a great way to describe it. Makes more sense to me now.

4
794 points at 99% Donor Moderator Repute WDFplus Member
Posted June 13 '09 at 03:44 PM
      Posts: 11,793
Tags like those are called "self-closing" tags. Any tag that can't contain other content (for example, an image, line break, horizontal rule, meta tag, etc.) must be self-closing.

In XML (and therefore XHTML), <foo></foo> and <foo /> are identical as far as the parser is concerned, but in reality, there are browser problems where you have to use one or the other. For example, you can't do <script type="text/javascript" src="foo.js" /> because most browsers don't properly detect the script tag as being closed.
filburt1, Web Design Forums.net founder
Want to advertise on this site?
Site of the Month contest: submit your site or vote for the winner!

5
9 points at 100%
Posted June 13 '09 at 06:35 PM
      Posts: 45
Normal WYSIWYG programs like Dreamweaver do this for you, although many people don't like to use these programs as they can add-in unnecessary code along with other problems ...still got my vote though.
Ali Hitch
Collossal Pixel - Web Design
http://www.collossalpixel.com

6
View stanneon's reputation
Posted June 18 '09 at 07:04 AM
      Posts: 8
There are only a few tags that don't need it and those would best be described as ones where content doesn't exist within them.
For example:
Line Breaks - <br />
Horizontal Rules - <hr />
In XHTML the traling "/>" acts as the closing tag.

This is right, the XHTML closing tag also applies to the image tag, we usually use <img src=""></img> right, but it's more easier now because instead of that we just close it after declaring the src="" or anything that follows after). <img src="" />

7
View nitin's reputation
nitin, WDF Noob Private message  
Posted July 2 '09 at 06:55 AM
      Posts: 14
Actually most of the html tags has ending tag. But there are some tags dont have end tag. For example break tag, hr tag dont have tag mostly these are the two which will use very useful in most of the coding.

Post Reply

Similar Threads
Thread Thread Starter Forum Replies Last Post
The future of Web Design Forums.net filburt1 Announcements 128 January 30 '10 04:27 AM
Simple question to help a lot fireseed HTML and CSS Help 1 February 5 '08 02:55 PM
Simple question - best way to create vertical padding between divs in CSS? TheGardener HTML and CSS Help 5 October 12 '07 12:14 PM
Should be a very simple question... twharry Web Design Discussion 1 August 11 '04 01:36 AM