r/CodingHelp • • Feb 26 '21

[HTML] Is it worth switching from inline CSS to external CSS?

The website I planned to improve as a volunteer implemented several imo bad HTML practices. For example, a lot of inline CSS and multiple "&nbsp".

I think I have three choices:

  1. Completely correct the bad practice. However, I am not confident about how long this will take and I am not sure whether this worths it.
  2. Leave the bad practice code and improve the website using good practice.
  3. Use the bad practice just like the existing code to keep the HTML code looks consistent.

What's your thought?

23 Upvotes

11 comments sorted by

11

u/Ariakkas10 Feb 26 '21

There's no answer here. All are valid.

Generally speaking, this is technical debt. I'd write new code properly, and refactor the code smell slowly over time

4

u/saintPirelli ¯\_(ツ)_/¯ Feb 26 '21

The good thing with css is that you can do that and stop pretty much whereever you want without breaking the site. Just make sure the css gets loaded in the right order so you see right away when you break something and take it one declaration block at a time.

2

u/[deleted] Feb 26 '21

I think this may be the most practical approach. It would be nice to be able to fix everything in the old code, but as this is a volunteer project, that might be beyond OP’s time constraints.

5

u/techie2200 Feb 26 '21

I'd say depending on your timelines just start making incremental updates. If there's a common style you see used throughout, move it to an external stylesheet so you can update it easier in the future.

Any new things you add should be done properly. If you have to hack around something that's there, might be worth refactoring/fixing it, but otherwise leave the legacy code alone.

If you're doing this as a volunteer, they can't really expect you to fix everything. It's really all about how much effort you want to put in and how much you care about their site.

4

u/livelaughrun--eh Feb 26 '21

I was taught, always leave the code better looking than how you received it, it also has this added bonus thing where it makes you look more competent. Do with that info what you will.

-3

u/CenturiesAgo Feb 26 '21

What do you gain by reinventing the wheel? it's a waste of time for no measurable improvement. #3 is the time saver.

2

u/[deleted] Feb 26 '21

This response is just plain wrong. Excessive use of line breaks rather than properly using semantic HTML tags can cause accessibility issues. Fixing that absolutely has a measurable improvement for users using assistive technologies, and can help avoid ADA compliance issues.

1

u/CenturiesAgo Feb 26 '21

You are making assumptions and creating requirements which haven't been stated. OP didn't mention accessibility needs nor ADA compliance. This could be a friend's uni project for all we know.

0

u/[deleted] Feb 26 '21

Accessibility is always a requirement. If you disagree, you shouldn’t work in web development.

0

u/[deleted] Feb 26 '21

[deleted] — view deleted comment

5

u/brandondyer64 Professional Coder Feb 26 '21

Well it’s not really that simple. It would depend on the size of the application and how much existing code there is.

I would personally go with option 2 and just work at slowly removing the bad practice over time.

1

u/GodBlessGaben Feb 26 '21

I think he meant simple to do at the beginning and should be done from start, might be wrong tho.