简体   繁体   中英

Semantic HTML tag for displaying a path/directory?

Is there any tag that's suited to markup a path or directory?

For example: <path>user/project/</path>

I've checked all new HTML5 tags but there doesn't seem to be one that fits this purpose. So which one would come close?

The code element represents a fragment of computer code. This could be an XML element name, a filename , a computer program, or any other string that a computer would recognize.

https://www.w3.org/TR/html51/textlevel-semantics.html#the-code-element

If it's part of code, you could use a code.path .

If it's some sample output you could use samp.path .

If you'd like to list the parts, you could use ol.path and style the way it's displayed:

<ol class="path">
  <li class="dir">user</li>
  <li class="dir">project</li>
<ol>

But if it's just a path, you should wrap it with span.path .

Unfortunately there isn't anything in HTML for that. You could try to wrap it in a <pre> tag or <code> in HTML5. Otherwise you can use a <span> tag and style it how you want it to look like.

What do you think about this:

<input type="text" value="user/project/" readonly="readonly" />

One advantage is that you can easily select the complete path without selecting other text accidentally. On the other hand it's not quite semantic since it's a form element.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM