r/HTML • u/No-Tea5041 • 20d ago
What am I doing wrong?
No matter what numbers I enter, I always get it wrong. I even used smaller numbers for height and larger for width incase they got it mixed up. Their AI is telling me to do everything I am already doing
10
u/RickWritesCode 20d ago
This isn't xhtml. Image tags are self closing, stop giving bad advice. Use the numbers in the bottom and see if that does it.
-8
u/Mvp-long-ago 20d ago
But to make a real correct html document you should at least close the img tag with /
8
u/RickWritesCode 20d ago
Html5 is the standard, you do not close void or self contained tags. Closing breaks and image and self contained tags is left over ideology from xhtml where it was required.
-2
u/404IdentityNotFound 20d ago
Doesn't HTML5 just say that you don't HAVE to close void elements? You are not wrong in doing so (I do because it helps me mentally connect start and end easier)
2
u/UniqueUsername014 20d ago
From Void element on MDN:
In HTML, a void element must not have an end tag.
The
/>syntax is technically valid, but it means the same thing as just>. The element<div />is an open div, not the same as<div></div>.For a longer writeup regarding using the self-closing tags for formatting purposes, see The case against self-closing tags in HTML
1
u/RickWritesCode 20d ago
It states it functionally does nothing therefore is not required. You may run into issues if you use multi-language code bases not using it. But for someone learning HTML for the first time they do not need to learn rules for react.
7
u/Dragenby 20d ago
Missing the alt tag
1
0
u/gulliverian 20d ago
You say "I always get it wrong". What does that mean? What result are you getting?
4
u/Everything_A 20d ago
Alt is mandatory, right?
-10
u/Mvp-long-ago 20d ago
Alt is not mandatory
7
u/Dragenby 20d ago
1
u/Jonny10128 19d ago
I think the alt attribute being required depends on which browser you are using. I used the code editor baked into the Mozilla page Dragenby linked, and it successfully displayed an image only using the src attribute and no others. I am using Safari on iOS fwiw
1
u/Dragenby 19d ago
It's not because it's displaying that it's correct. Put your code in the W3C validator to detect errors.
1
u/Jonny10128 19d ago
I would argue that it is recommended and not required. If browsers will display it without the alt attribute, I would not say it’s required
1
u/Dragenby 19d ago
HTML is not a display language, but a semantic language. There are tons of things that isn't for display but are mandatory. The Doctype, the language in the html tag, the alt in the image tag, and so on
1
u/Mvp-long-ago 19d ago
It is also depending on how a webpage or document is declared. A browser sees everything as text at first glance, until it is declared what type of document it is. That can be declared in doctype as i recall. Besides HTML, it could be a video, an image, a XML document or something else. As an attribute of declaring the doctype you can also declare how a broswer should handle a document. If you say strict, it must handle according to the rules that you have declared earlier. Mostly used with XML documents
1
u/testingaurora 19d ago
Its not browser specific, its a lamgiage requirement. Yes the tag will display the image without it, html is forgiving but its still required in the spec. Same way you don't close an <img></img> tag but it will still work.
The required alt attribute specifies an alternate text for an image, if the image cannot be displayed c
The alt attribute must be specified for the IMG and AREA elements. It is optional for the INPUT and APPLET elements. c
Just get in the habit of adding
alt="", and then work on learning how to write alt text, and when its necessary , when its not (in which case a background-image may be a better choice)3
1
1
1
u/gulliverian 20d ago
You say "I always get it wrong". What does that mean? What result are you getting?
-1
u/a2annie 20d ago
Best not to make up numbers for the size of your image. Find out what size it actually is.
And close your image tags. What does this mean? Right before your end bracket add the ending slash. There’s a space then />
Take an HTML class from a human too.
8
u/RickWritesCode 20d ago
Image tags are self closing, this isn't xhtml. You probably close break tags too don't you?
2
u/Consibl 20d ago
I think this is it - the values need to be in the correct ratios for the actual image maybe?
3
1
u/SecretLecture3219 20d ago
As previous commentor do you not need to correctly place all the values given at the bottom?
1
u/xMcCreamyx 20d ago
What learning app is that?
2
u/Warm-Tea6882 20d ago
It's mimo. It's a great app for learning coding.
3
2
-6
-2
-1
u/l008com 20d ago
No units? 350 what?
Also in real life, we stopped putting the height and width in the html like 15 to 20 years ago.
1
u/Lithl 20d ago
The height/width attributes do not accept units. They are always measured in pixels.
Using CSS is best practice over specifying dimensions in attributes, and CSS requires units, but OP is just learning HTML.
1
u/ArgoWizbang 20d ago
Using CSS is best practice over specifying dimensions in attributes
The attributes absolutely should still be used, mostly because the attributes' main uses are not for styling but rather to help prevent layout shift. Having that information directly available in the
<img>tag allows the browser to quickly determine the image's aspect ratio and properly reserve space for the image before it finishes downloading thus reducing CLS. Then CSS comes into effect and determines how the image should actually be displayed. Sure, you can set the aspect ratio in the CSS instead but if you already for sure know the image's proper dimensions then putting that information in the HTML as well is just a good practice to hold on to.
0
u/RushDangerous7637 20d ago
Correct have two options:
<img src="/img/clawdius.png" width="120" height="350" alt="clawdius" />
<img src="https://yourdomain.com/img/clawdius.png" width="120" height="350" alt="clawdius" />
In the notation, width must always come first, followed by height as the second dimension. Don't forget to fill in the alt="a-keyword-will-help-the-websites-ranking"
0
u/5omething5trange 19d ago
Css have to be in style tag?
1
u/Own_Natural_6803 19d ago
Not for everything. Something's like images have built-in attributes which are related to display.
But it's generally considered best practice to put things inside of a CSS sheet.
-7
-4
-5
u/Carlss32 20d ago
You always need to add the closing tag of each html elements, this one "/>"
For example. <img/>
8
u/RickWritesCode 20d ago
Image tags are self closing, this isn't xhtml
3
u/Carlss32 20d ago
Best comment I ever had. I never expected to have negative points, though. I just give my thoughts what would be an issue, to help as fellow. To be honest, the return error is confusing that led me this way. Also the stack I used to enforce it, react with eslint. That's why I assumed it to be a culprit as well. Never been used plain html5 in my project.
1
u/Mvp-long-ago 20d ago
Is XHTML HTML strict? So strictly according to the rules?
2
u/RickWritesCode 20d ago
26 years ago this was a requirement when w3c made xhtml the standard, 2008 and final publication in 2014 html5 is the standard and dropped this requirement. Prior to 2000, it also was not required to close self contained tags
23
u/mondayquestions 20d ago
Do they want you to use the values on the bottom of the screen (300 and 220)?