Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Best Practice: What tags should I wrap things like dates in?

Featured Replies

Was wondering what the best practice is, with regards to how to treat simple things like dates? Would wrapping them in span or em tag pairs be the most recommended thing to do?

 

I normally have the dates placed underneath a heading. Is it necessary to also add it into a div just for the sake of positioning, or can I really just use a span or em tag to settle it.

Edited by jesuis_danny

I'd advise against using a div in situations like this, in general it's best to avoid using too many divs on a page, as a date is still just standard copy you should use a p tag

<p></p>

 

Any copy on a page should really be contained with a p tag unless it's a list item (<li>).

  • Author

Any copy on a page should really be contained with a p tag unless it's a list item (<li>).

 

Thanks for the tip Alex.

 

Can anybody confirm Alex's statement? I was always under the impression that p tags should only be used naturally, for paragraphs.

Edited by jesuis_danny

Any copy on a page should really be contained with a p tag unless it's a list item (<li>).

 

I agree with jesuis_danny. This is debatable IMHO.

 

Just the date on it's own wouldn't be a paragraph.

 

If it's within another paragraph, I'd personally use a span within a <p> :

 

<p>This is a paragraph with the <span id='mydate'>Date goes here</span> within it</p>

 

If it's just the date floating about on it's own, then perhaps a <span> might be a better answer, as it is not a paragraph.

Apologies I haven't explained that nearly as well as I'd of hoped (lack of sleep I'm afraid), the p tag should be used to define paragraphs yes but what I meant was that there shouldn't be any copy sitting outside a p tag if it isn't in an li tag, for example:

<p>This is a paragraph</p> This is another paragraph

 

Personally I'd use a p tag for the date but it's really each to their own, whatever your more comfortable doing should be the method of choice (providing it's valid).

As above, we should really be coding for html5 now....

 

<time>26/7/2011</time>

 

Of course. That probably provokes the requirement of people to include xhtml or html5 in their question, as a lot of the time there will now be two answers.

Of course. That probably provokes the requirement of people to include xhtml or html5 in their question, as a lot of the time there will now be two answers.

 

I don't think professional designers/developers should be using XHTML anymore; HTML5 (at least the basic markup) is fully-supported with the HTML5Shiv in place.

 

HTMl5 gives you a lot of great options to keep your markup semantic and it makes styling MUCH easier since you don't have to give IDs to divs, you can just use an element name instead.

 

So yeah, go HTML5.

HTML5 (at least the basic markup) is fully-supported with the HTML5Shiv in place.

 

I wasn't aware of that, +1 for the heads up, again, Porky!

Gotta agree with above in that <time> would be the most current mark-up to go with.

Although you can only mark up precise dates within the Gregorian calendar but unless you're running a museum, i can't see this being a problem.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.