r/HTML

could someone please lead me to the right direction with my JS here?
▲ 0 r/HTML+1 crossposts

could someone please lead me to the right direction with my JS here?

I have been struggling to find out why my JS weather widget will not update the image strip to the correct icon. I have this :

<script>
fetch('https://api.open-meteo.com/v1/forecast?latitude=39.082222&longitude=-77.482222&daily=temperature_2m_max,temperature_2m_min&hourly=temperature_2m&timezone=auto&current_weather=true&forecast_days=1')

.then(response => response.json())

.then(data => {

console.log(data);

const weather = data.current_weather;

const daily = data.daily;

const targetLat = 39.082222;

const targetLon = -77.482222;

console.log('Low (F):', daily.temperature_2m_min[0]);

console.log('High (F):', daily.temperature_2m_max[0]);

console.log('Low (F):', Math.round(daily.temperature_2m_min[0] * 9/5 + 32));

console.log('High (F):', Math.round(daily.temperature_2m_max[0] * 9/5 + 32));

const targetCity = 'Lansdowne, VA';

const currentTemp = Math.round(weather.temperature * 9/5 + 32);

const iconCode = weather.weathercode;

// FIX: If currentTemp is much higher than the morning low, we adjust the displayed low

// to reflect the expected upcoming night low instead of the passed morning cold.

let lowF = Math.round(daily.temperature_2m_min[0] * 9/5 + 32);

console.log('Low (F):', lowF);

const lowTemp = lowF;

const highTemp = Math.round(daily.temperature_2m_max[0] * 9/5 + 32);

const weatherDiv = document.getElementById('weather');

console.log('Weather widget loaded completely.');

console.log('Icon code:', iconCode);

});

const weatherDiv = document.getElementById('weather');

const img = new Image();

img.src = 'https://i.ibb.co/WptyQH9y/image-strip-weather.jpg';

img.onload = () => console.log('Image loaded!');

img.onerror = () => console.log('Image error!');

function weatherCodeToIconURL(code) {

console.log('wttr code:', code, typeof code);

// FIXED: Translation map connecting Open-Meteo codes directly to your image strip positions

const openMeteoToSprite = {

0: "01d", // Sunny / Clear Sky -> First Icon

1: "02d", // Mainly Clear -> Second Icon

2: "02d", // Partly Cloudy -> Second Icon

3: "03d", // Overcast -> Third Icon (Your default)

45: "50d", // Fog -> Fog/Mist Icon

48: "50d", // Depositing Rime Fog -> Fog/Mist Icon

51: "09d", // Drizzle -> Light Rain Icon

53: "09d",

55: "09d",

61: "09d", // Slight Rain -> 4th/5th Rain Cloud Icon

63: "10d", // Moderate Rain -> Heavier Rain Icon

65: "10d", // Heavy Rain

71: "13d", // Snow Fall -> Snow Cloud Icon

73: "13d",

75: "13d",

80: "09d", // Rain Showers

81: "10d",

82: "10d",

95: "11d", // Thunderstorm -> Lightning/Storm Icon

96: "11d",

99: "11d"

};

// 1. ADD THIS SPECIFIC LINE BACK RIGHT HERE:

const spriteKey = openMeteoToSprite[code] || '03d';

// FIXED: Crisp percentage shifts that line up flawlessly when the image is scaled to cover the box

const positions = {

"01d": "0px 0px", // Sun

"01n": "0px 0px",

"02d": "-120px 0px", // Sun/Cloud

"02n": "-120px 0px",

"03d": "-240px 0px", // Cloud

"03n": "-240px 0px",

"09d": "-360px 0px", // Rain

"09n": "-360px 0px",

"10d": "-480px 0px", // Rain variation

"10n": "-480px 0px",

"11d": "-600px 0px", // Thunderstorm

"11n": "-600px 0px",

"13d": "-720px 0px", // Snow

"13n": "-720px 0px",

"50d": "-720px 0px",

"50n": "-720px 0px"

};

// CRITICAL CHANGE: We wrap the final variable so it fits your string perfectly

const pos = positions[spriteKey];

if (pos) {

// FIXED: Added transform: scale(2.5) to magnify the icon to a clear, readable size

return \<div style="display: inline-block; width: 3em; height: 3em; background: url('https://i.ibb.co/WptyQH9y/image-strip-weather.jpg') no-repeat center; background-position: ' + pos + '; background-size: auto; transform: scale(1.5); vertical-align: middle;"></div>`;`

}

// ADD THESE THREE LINES RIGHT HERE BELOW IT:

return 'Unknown code';

}

async function getWeather(lat, lon, city) {

var targetCity = city || 'Lansdowne';

var targetLat = lat || 39.082222;

var targetLon = lon || -77.482222;

var base = 'https://api.open-meteo.com/v1/forecast';

var query = '?latitude=' + targetLat + '&amp;longitude=' + targetLon + '&amp;daily=temperature_2m_max,temperature_2m_min&amp;current=weather_code&amp;timezone=auto&amp;current_weather=true&amp;forecast_days=2';

var url = base + query;

try {

var response = await fetch(url);

if (!response.ok) throw new Error('Status: ' + response.status);

var data = await response.json();

console.log('Min:', data.daily.temperature_2m_min[0]);

console.log('Max:', data.daily.temperature_2m_max[0]);

// Extract current conditions

var currentTemp = Math.round(data.current_weather.temperature * 9/5 + 32);

console.log('currentTemp:', currentTemp);

var iconCode = data.current_weather.weathercode;

// Initialize search tracking counters

var trueHigh = -Infinity;

var trueLow = Infinity;

if (data.daily.temperature_2m_min[0] &lt; trueLow) {

trueLow = data.daily.temperature_2m_min[0];

}

if (data.daily.temperature_2m_max[0] &gt; trueHigh) {

trueHigh = data.daily.temperature_2m_max[0];

}

// Convert raw Celsius trackers into Fahrenheit

var finalHigh = Math.round(data.daily.temperature_2m_max[0] * 9/5 + 32);

var finalLow = Math.round(data.daily.temperature_2m_min[1] * 9/5 + 32);

// FIXED: Directly assign lowTemp and highTemp to use your final calculations

var lowTemp = finalLow;

var highTemp = finalHigh;

weatherDiv.innerHTML = '&lt;p style="font-size: 16px; color: #fff; text-align: center; margin: 0 0 8px 0;"&gt;' + targetCity + '&lt;/p&gt;' + '&lt;div style="position: relative; text-align: center; margin-bottom: 8px;"&gt;' + weatherCodeToIconURL(iconCode) + '&lt;span style="position: absolute; top: 60%; left: 57%; transform: translate(-50%, -50%); font-size: 24px; font-weight: bold; color: #fff; filter: drop-shadow(-3px 0 2px #000);"&gt;' + currentTemp + '°F&lt;/span&gt;' + '&lt;/div&gt;' + '&lt;div style="display: flex; justify-content: space-between; width: 154px; margin: 0 auto;"&gt;' + '&lt;p style="font-size: 14px; color: #87CEEB; margin: 0;"&gt;Low: ' + lowTemp + '°F&lt;/p&gt;' + '&lt;p style="font-size: 14px; color: #FFA07A; margin: 0;"&gt;High: ' + highTemp + '°F&lt;/p&gt;' + '&lt;/div&gt;';

console.log('Weather widget loaded completely. Low Temp:', lowTemp);

// --- NOTE ---

// If you have lines that update 'weatherDiv.innerHTML', ensure they are right here!

} catch (error) {

console.error('Weather widget error:', error);

}

}

function fetchLocationAndWeather() {

// FIXED: Replaced slow browser popups with a silent, instant IP location lookup

fetch('https://ip-api.com')

.then(response =&gt; response.json())

.then(data =&gt; {

// Sends the visitor's dynamic coordinates and city name directly to your weather builder

getWeather(data.lat, data.lon, data.city);

})

.catch(error =&gt; {

console.error('Location error, falling back to Lansdowne:', error);

// Safety fallback: if the IP service fails, default to Lansdowne so the widget doesn't break

getWeather(39.082222, -77.482222, 'Lansdowne');

});

}

// FIXED: Added back the missing '/data/reverse-geocode-client?latitude=' string block

// RUN IT IMMEDIATELY

weatherDiv.innerHTML = 'Loading weather... 🌤️';

setTimeout(function() {

fetchLocationAndWeather();

}, 100);

// SET THE INTERVAL to repeat every minute

setInterval(fetchLocationAndWeather, 60000);
&lt;/script&gt;

And here is the CSS :

#weather {

display: flex;

flex-direction: column;

font: normal 12px Helvetica, Arial, sans-serif;

color: #fff;

}

And the HTML :

&lt;div id="weather" style="display: flex; flex-direction: column; font: normal 12px Helvetica, Arial, sans-serif; color: #fff; "&gt;&lt;/div&gt;

I really don't know what to do at this point... I'd appreciate any feedback, corrections, ....etc.

u/Accomplished-Rain-52 — 10 hours ago
▲ 0 r/HTML

HTML to PDF

Hey everyone
I just bought a uni book about Python
It Is a Pearson book so i can access to the html form of it
I have bought it physical
I would like to have it in pdf
Is there a way that a can do that?
I know Pearson ad an application that I can use to study on it but it doesn’t give me access
Thanks in advice

reddit.com
u/Hefty_Ad_1762 — 12 hours ago
▲ 0 r/HTML

Why can't anyone build a decent deployment platform for plain HTML?

I think Vercel, GitHub Pages, and Cloudflare are still pretty unfriendly for normal users / non-tech people.

reddit.com
u/chrischen-003 — 24 hours ago
▲ 4 r/HTML

Which online channel ?

I am 12 th passed student and getting a tier 3 collage so I want to learn html online but I didn't understand english 100 percent so any channel in hindi that make me master in html

reddit.com
u/nit9271 — 22 hours ago
▲ 2 r/HTML

Which online channel follow?

Which youtube channel I can follow to improve my coding skill I am just passed 12 th and my collage is tier 3 so which channel I follow to master htmel and css online

reddit.com
u/nit9271 — 22 hours ago
▲ 6 r/HTML+1 crossposts

Built a warm minimal portfolio template in pure HTML CSS — designed for photographers and creatives

Been building a set of HTML and CSS templates

lately, each one with a completely different

aesthetic direction.

This one is for creative professionals —

photographers, illustrators, designers — who want

something elegant rather than techy.

Design decisions I made:

- Cormorant Garamond serif for headings — refined

and distinctive without being overdone

- Warm cream and charcoal palette — completely

different from the typical dark tech template

- Split hero layout with image placeholder and

live stats row

- Work grid with subtle scale hover effect

- Services list with animated arrow on hover

- Testimonials section inverted to dark background

for contrast

- Full contact section with social links

Everything is pure HTML and CSS. No frameworks,

no JavaScript libraries, no dependencies.

Opens straight in a browser.

About 700 lines of clean CSS using custom

properties so the entire color theme changes

in a few seconds.

Happy to answer questions about any of the

CSS decisions or share specific code snippets.

▲ 7 r/HTML

Made an editorial landing page template in pure HTML CSS — sharing the approach I used (unfortunately it scales images wrong)

Wanted to share a landing page template I built

recently. The challenge I set myself was making

something that looks genuinely designed rather

than generated — no frameworks, no JavaScript

libraries, just HTML and CSS.

Main things I focused on:

- Strong typographic hierarchy using Playfair Display

- CSS Grid for the editorial column layout

- CSS custom properties for easy theme customization

- A scrolling ticker built with pure CSS animation

- Mobile responsive without any media query hacks

The whole thing is about 600 lines of clean CSS.

No dependencies. Opens straight in a browser.

Happy to answer any questions about the approach

or share specific code snippets if useful.

u/Psychological_Ad8008 — 2 days ago
▲ 11 r/HTML

what does ?ra=m on a link mean?

hi!! i hope this is the right place to post, i'm just trying to get the answer to the above. recently when i open youtube in a browser (specifically duckduckgo, if it's relevant), my youtube links have that at the end. attached image for the different between ddg and chrome. anything to be concerned about? i can't find information anywhere and i'm usually pretty good at internet searching so i'm a little worried. thanks in advance!!

u/nayutaens — 3 days ago
▲ 6 r/HTML

how can i improve this a bit

how to improve this

u/8Kubek — 5 days ago
▲ 0 r/HTML

Want to learn HTM N CSS

want to learn HTML and CSS from scratch but idk where to start 😭
Too many resources on youtube and google got me confused
Any good roadmap or channel for beginners?

reddit.com
u/Xearsyrith — 5 days ago
▲ 1 r/HTML

Overflow-y not working :(

I’m currently making an HTML code meant to look like little browser windows. it’s my first time overlaying one container over another (the first container being the image, the second being the scroll container where all the wording will go).

I want the container to scroll Y (aka, down and up). but every time I run the code, it scrolls X (side to side). i dont know what I’ve done wrong.

if anyone has any suggestions please tell me!!! thank you :D

code:

<code><div class="square" style="height:369px;width:400px; position: absolute; background-image:url(https://64.media.tumblr.com/8076322320a5ff7c06279bfcc038bfe7/f0f2243e5da7d4a2-5f/s1280x1920/b7901ca612bfb1ca062c59b59584b8d5c15d2440.pnj);background-size:cover;background-position:center center; background-color:transparent;border:1px solid #FFFFFF; border-radius: 0px;"> <div class="square" style="height:174px;width:337px; position: absolute; left: 30px; top: 78px; background-image:url(IMAGE URL GOES HERE);background-size:cover;background-position:center center; background-color:transparent;border:1px solid #FF0000; overflow-y: auto; padding: 10px; border-radius: 0px;"><span style="font-size: 32px;">SCROLL NORMAL WHAT THE FUCKCKCKCKCKCKCKCKCKCKCCKKCCKKCCKCKw<br></span></div>

</code></div>

u/ivy_vinezz — 4 days ago
▲ 169 r/HTML+3 crossposts

Who still remembers this HTML tag? 👇

Although it has been deprecated for such a long time (really long time), it's still supported by all browsers!

Anyway, not advised to use in production!

Oh man, we are so old ... 😑

u/wanoo21 — 7 days ago
▲ 6 r/HTML

Basic website, how to hide phone number and email address from bots?

Do I need to add a form to the website? I don't want to do that. I just want the website to look like:

My Cat

here are some pictures of my cat

pic, pic, pic

Email my cat at Cat@gmail.com

Phone my cat at 102-123-1234

obviously this is not a cat website, it is a business, but I hope you get the idea.

reddit.com
u/GodsCasino — 7 days ago
▲ 9 r/HTML

I need help for my group project

https://preview.redd.it/bgorep2zxo1h1.png?width=1918&format=png&auto=webp&s=297f01dca3679469f1e0859afe8a1869727f721a

I was just putting the info in the <main> section when suddenly it becomes like this. It's originally supposed to the next picture before i put the content.

https://preview.redd.it/g0urr5y7yo1h1.png?width=1918&format=png&auto=webp&s=35e851e55c7ec109ce68ed1f8355e168f87637fc

I tried telling anyone and even using ai to fix this but no progress. Can someone please what's wrong with it?

reddit.com
u/MisterDaydreamishere — 6 days ago
▲ 4 r/HTML

I made a (still basic) interactive web atlas with information about countries

I made a web atlas that still contains the most basic facts, still nothing too complicated. It lets you see elementary facts about a country:
https://aldomym.github.io/web-atlas/

What do you think I should add to make it more engaging for users?

reddit.com
u/Glittering_Report_82 — 5 days ago
▲ 51 r/HTML

What's a bad HTML habit beginners should stop doing early?

I've been reviewing beginner projects lately and keep noticing things like:

  • excessive div nesting
  • inline styles everywhere
  • missing semantic HTML
  • using br tags for spacing

What are some habits you think are worth fixing early?

reddit.com
u/Top-Run-7508 — 8 days ago
▲ 1 r/HTML

Need help!! MP3 audio won’t source for project!

My girlfriend’s got a project - a website created with html. We’re having severe issues adding her MP3 audio file. She has the code right, and i’ve even gone through and done it myself. The little audio play/pause button pops up on live mode but shows 0 seconds of audio, probably because it’s not linked. The MP3 file is directly next to her Index file. It refuses to source the file, and when the file is dragged in it pops up coded out and still refuses to source. We’ve tried to use a new MP3 audio and still nothing.

I know the path or something must be messed up but this project has literally brought us both to tears trying to figure it out. I’ve sat and watched so many video and read so much that was talking about everything BUT our situation. I cannot find anything on it refusing to source the file. I only learned all of this helping her so sorry if i messed up explaining. Any and all help is appreciated and i can give more info.

edit: we got it!! not sure how but it decided to randomly pop up when typing the source file stuff, didn’t even have to change anything! thank you so so much for the help!!

reddit.com
u/Brave-Row-9581 — 5 days ago
▲ 2 r/HTML

Print header

en: Please help, how can I fix this so the header doesn't overlap the page content and leaves some spacing? I tried using margin-top, but it only works on the first page.

ру: Помогиие пожалуста, как это исправить чтобы header не налаживался на содержимое страницы и был какойто отступ я пытался сделать через margin-top но он работает только на первую страницу.

u/23013_A7 — 6 days ago
▲ 10 r/HTML

Img lose quality

I just programmed a website that shows an envelope and a letter as a gift for my girlfriend. I used some designs I made for the envelope and added them in SVG format, but when I open the website the designs lose quality and don’t look good. What can I do to fix this?

u/Blackshark34 — 8 days ago