BOSTON -- Kids these days are glued to technology, constantly on their cellphones, tablets or laptops, yet they know little about how they function. Starting this fall, tens of thousands of Massachusetts students will be able to explore how these gadgets work while in the classroom.

At the high school level, students in an optional introductory computer science course will be taught how to build a mobile app, create online graphics and code computer programs and web pages. Elementary and middle school students will learn basic skills that are intertwined into lesson plans focusing on computer commands and functions and explanations on how data works, said Roxanne Emadi, a social strategist at Code.org, a nonprofit that is leading the initiative to bring computer science to schools nationally.

"No matter who you are or where you are from, it is important to know how technology works and how it is made," Emadi said. Learning computer science also boosts creativity, problem-solving skills and confidence, she said.

Besides preparing youth for potential careers in computer science, these skills will help students in practically every field they pursue after graduation, said Jim Stanton, executive director of MassCAN, a nonprofit that promotes computer science in Massachusetts schools.

Fields such as health care, transportation and finance are guided by computer-driven software, Stanton said. "The more people who know about the software programs that manage their disciplines, the better they can help computer scientists to design them to fit their needs," he said.

Half of all jobs in science, technology, engineering and math require some form of computing expertise, according to U.S. Bureau of Labor statistics from 2010.

More than 60,000 students in 12 Massachusetts public school districts will have the opportunity to take computer science courses paid for by Code.org. The nonprofit will cover all costs including providing the curriculum and teacher training, which is sponsored by companies such as Microsoft Corp. and Google Inc. Nationally, 30 public school districts including New York City’s and Chicago’s have partnered with the organization.

In Andover, there has been a high demand for such classes for a while, said Johanne Najarian, director of digital learning at the town’s public schools.

"We have wanted to offer more computer science courses but it is so difficult to find and pay for teachers who are qualified to teach them," Najarian said. "When Code.org offered to partner with us and provide the curriculum and training, it was just a no-brainer," she said.

Although organizations are pushing to make computer science classes mandatory in high schools, the Massachusetts Department of Elementary and Secondary education has argued that schools would have to train and hire new teachers, which would be too costly an endeavor for some districts.

But founder and CEO of Code.org, Hadi Partovi, said the face of computer science courses is predominantly white, affluent men, and that will change only if more students are introduced to the field at a younger age.

"We need to put computer science courses on the menu in schools so all students have the opportunity to pursue these high-paying technology jobs," Partovi said.