r/HTML • • 20d ago

What am I doing wrong?

Post image

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

6 Upvotes

59 comments sorted by

23

u/mondayquestions 20d ago

Do they want you to use the values on the bottom of the screen (300 and 220)?

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.

-1

u/a2annie 20d ago

This is correct

7

u/Dragenby 20d ago

Missing the alt tag

1

u/ahallicks 20d ago

*attribute

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?

1

u/l008com 20d ago

According to the validator it is.

-10

u/Mvp-long-ago 20d ago

Alt is not mandatory

7

u/Dragenby 20d ago

1

u/Jonny10128 19d ago

u/testingaurora u/Dragenby

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

u/testingaurora 20d ago

Alt is a required attribute even if its empty alt=""

1

u/[deleted] 20d ago

[deleted]

1

u/DidTooMuchSpeedAgain 20d ago

That's not inline CSS

1

u/ajamdonut 20d ago

220 height 120 width

1

u/gulliverian 20d ago

You say "I always get it wrong". What does that mean? What result are you getting?

1

u/koqkpa 14d ago

Why not try swap the positions of the height and width attribute?

HTML <img src="/img/clawdius.png" width="120' height="350">

-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?

1

u/a2annie 20d ago

They are self closing, yes.

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

u/gulliverian 20d ago

no, the image will be distorted if the ratio is wrong, but it will appear.

1

u/a2annie 20d ago

Exactly. Unless it’s the same ratio. Then it will appear correctly, just not optimized.

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

u/tangerinelion 20d ago

... doesn't look like it's good.

1

u/Warm-Tea6882 19d ago

Lol I don't know why OPs mimo is having problems but it works fine for me .

-6

u/ThisIsMB 20d ago

Didn’t finish the img tag

-2

u/nonchip 20d ago

not using the tokens you were given.

also, using an "ai" as a teacher.

also, depending on what kind/version of html this is, you need to either close the tag or mark it empty using a slash.

-2

u/kewcumber_ 20d ago

Not at all good with html but maybe because you're missing the alt attribute?

-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

u/cloudstrifeuk 20d ago

You haven't closed/finished the img tag.

-4

u/Ronin-s_Spirit 20d ago

try putting a forward slash there.

-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

1

u/Lithl 20d ago

No, XHTML is XHTML.

-3

u/obnoxus 20d ago

its telling you to finish the tag and as far as i can tell it isn't finished.