Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 3297

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 61k
Author
Asked: November 26, 20242024-11-26T01:25:07+00:00 2024-11-26T01:25:07+00:00

Attributes in HTML – Web Development for Toddlers

  • 61k

Last we talked about HTML elements and their syntax!
We came across an odd looking piece of code, that went like this

<img src="https://picsum.photos/200/300" /> 
Enter fullscreen mode Exit fullscreen mode

The syntax for an attribute goes like this:

<tag-name attribute-name="attribute-value"></tag-name> 
Enter fullscreen mode Exit fullscreen mode

And if you compare the syntax with that image example, we find an attribute, with attribute-name “src”, and attribute-value as an URL to the image that's stored on the internet.

There can be multiple attributes associated with an element

Tons of them actually, and that's pretty common to see.
So how do you go about making that happen?
Here's a syntax breakdown

<tag-name attribute-name1="attribute-value1" attribute-name2="attribute-value2"></tag-name> 
Enter fullscreen mode Exit fullscreen mode

A real life example would look something like this:

<input type="password" name="userPassword" class="standard-input" /> 
Enter fullscreen mode Exit fullscreen mode

And if none of these make sense, don't worry, we'll get there.
But you get my point, don't you?

From a surface level classification, we can categorise attributes on two sets of bases

Attributes which have some value

Like the ones we saw, there are some attributes that might contain some data, for example:

<button class="btn btn-primary">  Click Me! </button> 
Enter fullscreen mode Exit fullscreen mode

Now what does this class attribute do? We'll discuss that in the next chapter.

Attributes which don't have any value

There are some attributes that don't need any value, for example this bit of code with make the render the button as unclickable (try running it in JSBin)

<button disabled>  You can't click me </button> 
Enter fullscreen mode Exit fullscreen mode


Now the second way we can categorize attributes would be

Common attributes

These attributes can be applied on pretty much every element there is, some of them might be: “id”, “class”, “name” etc.

<button class="btn">Click Me</button> <hr class="make-me-red" /> <div class="is-should-be-a-box"> I am not a box yet, we'll need to learn CSS to do so! </div> 
Enter fullscreen mode Exit fullscreen mode

Although those class attributes and their values seems to do nothing in this example, we'll get to them when we start CSS in a few chapters.

Element specific attributes

There are some attributes which if applied with a combination of possible values, will direct the browser to function a bit differently.
For example the “type” attribute for “input” elements.
Run this code in the browser and see for yourself!

<input type="text" placeholder="This is a text input" /> <input type="password" placeholder="This is a password input" /> 
Enter fullscreen mode Exit fullscreen mode

Try writing something in those inputs which just popped up! Did you see that?
The second input (password one) hides whatever you type, that's because we instructed the browser to do so (with the attribute type).
Also the attribute “placeholder” is “input” element specific. That means if you try to use this attribute on any other element, the browser wouldn't know what to do with it and won't make any difference.

Consider this

<div placeholder="Some value that makes no difference">     See! "placeholder" is uselss here </div> 
Enter fullscreen mode Exit fullscreen mode

Custom Attributes

The standards says if we ever want to store some of our values in the form of an attribute with an element, we do so with attributes prepended with “data-“.
Now this won't make any difference, but it just helps us differentiate between native attributes (or the common + element specific ones) vs custom ones (the ones we create).

Now for example

<div custom-attribute="custom-value"></div>  <div data-custom-attribute="custom-value"></div> 
Enter fullscreen mode Exit fullscreen mode

Both of these are acceptable! But let's follow the standards (remember that animal analogy!).

That being said, why would we use custom attributes or to be more precise any attribute at all that does nothing in the browser output!?

Well, that's because element specific attributes only work because the browser's render engine is programmed to do something with it. Similarly we can use JavaScript to make use of these custom attributes or any attribute we'd like to do something that we want.
And we'll do so! in a couple of chapters, after a bit of CSS.

beginnershtmltutorialwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    ES6 - A beginners guide - Template Literals

    • 0 Answers
  • Author

    Understanding Higher Order Functions in JavaScript.

    • 0 Answers
  • Author

    Build a custom video chat app with Daily and Vue.js

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.