Defining my own tags in HTML

html custom tags css
html custom tags w3schools
custom html examples
custom html element
html define element
html tags
define new html tag
non standard html tags

I have a paragraph in my website in which I have to highlight few words. Instead of using div and a class, I used a tag which I name myself as follows

<html>
    <head>
        <style>
            highlight{
                background-color:#FFF176;
            }
        </style>
    </head>
    <body>
        A quick <highlight>brown</highlight> fox jumped over a lazy dog.
    </body>
</html>

Here is the JSSFiddle

It seems to work fine. But is there anything wrong with this? Is it okay if I use it for a project?

Though it is alright to do that, I would suggest the following: https://jsfiddle.net/838Lrnwk/

<html>
<head>
    <style>
        #high .highlight{
          background-color:#FFF176;
        }
    </style>
</head>
<body>
  <p id="high">
      A quick <a class="highlight">brown</a> fox jumped over a lazy dog.
  </p>
</body>

This would give the same effect; however, you can control what paragraph has the the effect in and all other tags like font,em, strong, etc and still retain the highlight.

How to create custom tags for html, Tags, attributes, and nesting are all there is to HTML's declarative API for Because of that developers have to create their own custom UI components. Those solutions use classes to define both the component type and its  With HTML you use the  tag, for example, to show bold text. If you need a list, then you use the  <ul> tag with its child tag  <li>  for each list item. Tags are interpreted by browsers and, together with CSS, determine how the content of a webpage is displayed and also how parts of the content behave.

There is nothing wrong in using custom tags. However, you didn't define the tags you used. Please see the links below to articles on proper ways to user custom tags/elements.

  1. Using custom elements
  2. Extending HTML by Creating Custom Tags

Custom HTML Tags - DEV Community ‍ ‍ , From a practical point of view, you define your own HTML tag. Before I start to develop my own example I'd like to show you an example  Now that you know how to define the purpose of your site, create a project outline and create a file folder structure, it's time to move on. In this tutorial, you will learn about HTML editors, HTML tags, CSS, and how to create your first web page using the infamous "Hello World" programming example.

You can use this solution in a project, functionally it's ok but is advisable that you attach your tags with a common classname to define styles sheets (CSS), tags structures (HTML) and functionality (JavaScript) in differents source files.

I recommended you to put in a different file your CSS styles with a link-tag inside the head tag like this:

<head>
    <link rel="stylesheet" type="text/css" href="theme.css">
</head> 

In this pages you can learn much more about it:

MDN Web Docs Mozilla

Define Your Own HTML Tag!, Example #1: Creating a Gravatar Custom HTML Tag To have our custom tag actually display the Gravatar picture for my email, we have to Using the customTag() function, you can easily develop your own custom tags. Yes, theoretically :) Here’s an example: Custom HTML tag test (tested in Chrome) You can add any custom tag you want. As long as you declare it and style it properly, you should see you style directives take form.

Extending HTML by Creating Custom Tags, These allow you to create your own HTML elements along with their own You can define a JavaScript API for your custom element that  Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java and XML.

How to Create Custom HTML Elements, a while back where some kid was asking “Can I make up my own HTML tags? H2, H3 tags, etc., having some pre-defined attributes and usages, one could  You can create custom html tags with following steps: Step 1- Register a new Element. Custom elements are created using document.registerElement(): var XFoo = document.registerElement('x-foo', { prototype: Object.create(HTMLElement.prototype) }); 2nd argument in registerElement is optional object which describes the element's prototype.

Can You Use Your Own, Completely New, Made-Up HTML Tags , Custom elements allow web developers to define new HTML tags, extend Custom elements can manage their own content by using the DOM  Depends on what you define HTML as. I think of HTML as a language based on SGML, with a specific set of elements and attributes. XHTML is a variant on XML, with a specific set of elements and attributes that's a lot like HTML's. When you use your own attributes, it is still SGML of XML, but no longer HTML of XHTML in my opinion.

Comments
  • Thanks. I think this is a better method because it passes the HTML validation by W3 too.