To contribute to and elucidate the participation of microbiota in celiac disease (CD) and type 1 diabetes (T1D) development, we evaluated the influence of HLA haplotypes, familial risk, and diet on the microbiota of schoolchildren. We conducted a cross-sectional study on 821 apparently healthy schoolchildren, genotyping HLA DQ2/DQ8, and registering familial risk. We analyzed the fecal microbiota using 16S rRNA gene sequencing, and autoantibodies for CD or T1D by ELISA. After analyses, we created three groups: at-high-risk children (Group 1), at-high-risk children plus autoantibodies (Group 2), and nonrisk children (Group 3). HLA influenced the microbiota of Groups 1 and 2, decreasing phylogenetic diversity in comparison to Group 3. The relative abundance of Oscillospiraceae UCG_002,Parabacteroides,Akkermansia, andAlistipeswas higher in Group 3 compared to Groups 1 and 2. Moreover, Oscillospiraceae UCG_002 andParabacteroideswere protectors of the autoantibodies’ positivity (RRR = 0.441 and RRR = 0.034, respectively). Conversely,Agathobacterwas higher in Group 2, and Lachnospiraceae was in both Groups 1 and 2. Lachnospiraceae correlated positively with the sucrose degradation pathway, while the principal genera in Group 3 were associated with amino acid biosynthesis pathways. In summary, HLA and familial risk influence microbiota composition and functionality in children predisposed to CD or T1D, increasing their autoimmunity risk.