Could I use a src attribute on a `<p>` tag to load in raw text?

Question

Could I use a src attribute on a <p> tag to load in raw text?

Answer

No. Unlike the global id attribute, the src attribute can only be applied to specific tags of which the p tag is not included. In other words, not all attributes are available to every tag. To find out which attributes are available to every tag, take a look at this list of global attributes.

15 Likes

Where is i can find information about link between raw text and src attribute?

p.s. it’s my first message at the codeacademy forum, congrat me!

11 Likes

There is no link between the two. All HTML is raw text. src is an attribute that takes a URI as a value. Only a handful of elements have this attribute.

img
audio
video
embed
iframe
source
script

As for populating P elements from an external source, that would have to be done in the DOM using AJAX, which will come up later in the course. For now, be content to write all content directly to the HTML document raw source.

31 Likes

no, you can make a text contain an URL by using the element called β€œa” between that text. Hope this help

Can we add any attributes to the <p> tag, or its just mainly use for text

The <p></p> node is a sectioning element that may contain other elements, but it is specifically geared to contain text and inline elements, as opposed to other block level elements. Most inline elements are aimed at text content such as,

<span></span>
<em></em>
<strong></strong>
<i></i>
<img>

The latter is an inline-block but can be wrapped in a P. Modern HTML provides a better element for this, though: <figure></figure>.

As for attributes we would need to check the specs in the W3C HTML Elements page to see which are permitted attributes. We don’t generally use attributes other than class and id for paragraphs.

p – paragraph - HTML5

Thanks for the reply, really appreciate :pray:
To my understanding there are special attribute for <p></p> and i want to know these special attributes it is only use in <p></p> or can be use in other tags

1 Like

Tags have meaning, which has always been the case, but which has been greatly enhanced in HTML5 with the introduction of semantic elements.

That said, consider also that the tags are meant to be human readable. The browser cares nothing about what tags (elements) we deploy. It is humans and user agents that need to be informed of overlying meaning and structure of our document.

A paragraph is primarily a text container and should be used consistently in that role. Using other elements to contain text is not forbidden, nor uncommon, just thoughtfully composed as such. In general terms, it is preferred we use paragraph markup.

There are a good many sectioning elements and document structures for us to draw upon. We will employ list elements in many ways such as navigation, sequential presentations, etc., not just text lists. Likewise we will often employ tables to organize and structure our data within the document.

Bottom line, for now and until you become more familiar with all the elements and their purposes one suggests using P elements exclusively as text containers and reach for something else to contain other content. This will help you to develop good habits and for future planning when writing documents from scratch.

thanks for the reply, i have another question
can <p></p> be a parent tag to <div></div>
like this <p>----

---
-----</p>

1 Like

As mentioned earlier, we can write block level elements inside a P, but it is not the sort of practice one can see as recommended. For one, there is no semantic relationship of the textual body of a paragraph and a block level element of any sort. As mentioned above, the most suitable child elements for a P are all the inline elements as they can markup text within a paragraph, such as emphasis, underlining, bolding, or isolating (as in a change of language, for instance).

There are so many other sectioning elements that have a much looser definition than does a paragraph. In other words, we would expect to see paragraphs in a section, a div, an li, a blockquote, an article, etc. but we would not expect to see any of those inside a P. It is not meant for that purpose, given all of the above are better choices.

okay thanks for clarifying it :pray:

1 Like