Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

James Nelson
23,956 PointsAnchor element
Hello,
I have always been under the impression that the anchor element being inline, should always be surrounded by some sort of block element such as a paragraph element. Am I right in thinking so?
4 Answers

Charalampos Anargyrou
14,031 PointsHaving <a> tags which are not inside a block element will fail to validate under XHTML 1.0 Strict. It validates fine in HTML5.

Adam Sackfield
Pro Student 19,663 PointsAn anchor element is inline by default. However you can set it to display: block; or any other property.

James Barnett
39,199 PointsAn <a>
is usually used in the context of a block of text or a list however, it can function as a button in which case you don't have to wrap it in a <div>
or any other block element.

Jeremy Germenis
29,854 PointsI am under the assumption that inline elements always reside in a block element. Using an anchor as a button does not change the fact that it is still an inline element and goes inside a block element. I can set a paragraph's display with css to inline but that does not change the relational meaning of a paragraph to the browser. I have only changed the visual aspect of the paragraph and it is still a block element.

James Barnett
39,199 Points>
I am under the assumption that inline elements always reside in a block element.
I don't think it works like that.
If you create a page that only has a <span>
element on it then inspect it, you won't see any block elements in the DOM.
further reading

Jeremy Germenis
29,854 PointsMaybe I was not clear. Inline elements should reside in a block element, semantically speaking. You should not have a page with just a span on it.

Jeremy Germenis
29,854 PointsBy the way.... the body element is a block element.
James Barnett
39,199 PointsJames Barnett
39,199 PointsLearned something new today.
HTML 4 Strict & XHTML 1 Strict it fails validation, in HTML 4 Transitional, XHTML 1 Transitional & HTML 5 it validates.
James Nelson
23,956 PointsJames Nelson
23,956 PointsThat would make sense as I haven't dabbled into the world of HTML5 as of yet
James Barnett
39,199 PointsJames Barnett
39,199 PointsIf you are using a doctype of
<!DOCTYPE html>
then you are already using HTML5.James Nelson
23,956 PointsJames Nelson
23,956 PointsI tend to use XHTML 1 Strict. Its good practice for beginners to use, drills better markup into a student I think
James Barnett
39,199 PointsJames Barnett
39,199 PointsI think you are probably right, if you faithfully validate all of your markup against that standard.
On the topic of good markup I consider this to be the gold standard
James Barnett
39,199 PointsJames Barnett
39,199 PointsHere's the link to the post that image came from: http://css-tricks.com/what-beautiful-html-code-looks-like/
My 2 favorite sources for markup style are:
I assembled those into my own personal markup style guide