Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Data atribute or CSS style in HTML document

Hy,

I want let user to customize his profile page (like background color/image, text color and so on).

I would like to know what is the best solution for this. Should I use "data attributes" or I should simply add "style" into html document.
With data attributes i should have javascript but I don't see point of using it (maybe I miss something) if I can simply add styles.
Can anyone suggest me solution for this?

Code
<div class='test' data-bg-color="red" >teste</div>
//script to change body color
or
Code
<div class='test' style="background-color: red; >teste</div>
Or should I put all profile content into one div and then style that div?

Thanks.
Don't quote me, but I'm pretty sure it's better to use class selectors unless you're trying to store data or just need customize a specific element. I personally don't even use them unless I'm working on existing site, makes it way easier.
Skype: ryand.8
[Image: XbaG5gl.gif]
For my custom built WordPress themes, I just echo out the field they want as inline if it's for e.g a background image. No need for messing about/adding more files than needed, what's the point imo.
Web Designer / Developer & SEO Expert.

View Work
Earn 10% of the job you refer me to!

Skype aerox.design

If you're selecting from a premade list, always use a styled class. It's not even recommended that you would allow user input that lets them choose the color from an input. You're opening yourself up to a world of vulnerabilities.

Let them select a list of colors (Eg. Colors 1-8) and send the ID to a server. Never take the input at face value (Eg. <option val='#FFFFFF'></option>), use something like "<option val='1'></option>" and let the server make the relation between colors.

1 = #fff,
2 = #000,
etc

As for the classes etc, why would you iterate through the data attributes to apply the classes/styling? Makes no sense. Just do it at the time of loading using either a class (I would recommend that, for sake of simplicity) or inline styling.
Je t'aime
[Image: fpZ5a5g.png]
(Apr 22, 2022 04:39 PM)-Scrub Wrote:  Jokes on you, I'm not smart enough to know what he's talking about.
Thanks all for help.

(Mar 8, 2018 07:19 PM)Nachfolger Wrote:  It's not even recommended that you would allow user input that lets them choose the color from an input. You're opening yourself up to a world of vulnerabilities.

This is exactly what i want to do (let user to chose any color). Make input field where user can "write" color hex code for specific element.

I don't understand what you thought by "opening yourself up to a world of vulnerabilities" because I would add some input check (to make sure that user wrote color hex code).
There is color pickers available in HTML5.
Depends what sort of backend your working with I guess for this sort of question though.
https://www.w3schools.com/colors/colors_picker.asp
Web Designer / Developer & SEO Expert.

View Work
Earn 10% of the job you refer me to!

Skype aerox.design



Possibly Related Threads...
Thread / Author Replies Views Last Post
by HackersSep 28, 2026 01:50 PM 9 360 Sep 28, 2026 01:50 PM
Last Post: JuWacky
by oxagastSep 3, 2022 07:52 AM 0 196 Sep 3, 2022 07:52 AM
Last Post: oxagast
by AerrowsGirlfriendJun 16, 2021 04:17 AM 1 317 Jun 16, 2021 04:17 AM
Last Post: Nachfolger